Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I format a javascript date to be serialized by jQuery

I am trying to set a javascript date so that it can be submitted via JSON to a .NET type, but when attempting to do this, jQuery sets the date to a full string, what format does it have to be in to be converted to a .NET type?

var regDate = student.RegistrationDate.getMonth() + "/" + student.RegistrationDate.getDate() + "/" + student.RegistrationDate.getFullYear();
j("#student_registrationdate").val(regDate); // value to serialize

I am using MonoRail on the server to perform the binding to a .NET type, that aside I need to know what to set the form hidden field value to, to get properly sent to .NET code.

like image 978
Sean Chambers Avatar asked Aug 27 '08 14:08

Sean Chambers


People also ask

How do you serialize data in JavaScript?

In JavaScript, for example, you can serialize an object to a JSON string by calling the function JSON. stringify() . CSS values are serialized by calling the function CSSStyleDeclaration. getPropertyValue() .

What is the use of serialize () method in jQuery?

The serialize() method creates a URL encoded text string by serializing form values. You can select one or more form elements (like input and/or text area), or the form element itself. The serialized values can be used in the URL query string when making an AJAX request.

What is the date format in jQuery?

format = All input formats valid for jQuery. format. date are valid for this method. The defaut format is MM/dd/yyyy HH:mm:ss.


1 Answers

This MSDN article has some example Date strings that are parse-able is that what you're looking for?

string dateString = "5/1/2008 8:30:52 AM";
DateTime date1 = DateTime.Parse(dateString, CultureInfo.InvariantCulture); 
like image 69
travis Avatar answered Oct 04 '22 21:10

travis