How can I format javascript date for jQuery serialization

I am trying to set javascript date so that it can be passed via JSON to the .NET type, but when I try to do this, jQuery sets the date to a full string , in what format should it 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 use MonoRail on the server to bind to the .NET type, which aside I need to know why I need to set the value of the hidden form field in order to correctly send .NET code.

+4
source share
3 answers

This MSDN article contains an example of a date string that is syntactic - is this what you are looking for?

 string dateString = "5/1/2008 8:30:52 AM"; DateTime date1 = DateTime.Parse(dateString, CultureInfo.InvariantCulture); 
+2
source

As travis suggests, you can simply change the property of a parameter or class (depending on what you pass back) into a string, analyze it as an example.

You can also take a look at this article . This suggests that the direct conversion to serialize DateTime JSON uses something more than the ticks property.

+2
source

I suggest you use the YYYY-MM-DD notation, which offers the best combination of uniqueness and readability.

So:

var regDate = student.RegistrationDate.getFullYear() + "-" + student.RegistrationDate.getMonth() + "-" + student.RegistrationDate.getDate(); j("#student_registrationdate").val(regDate);

+1
source

Source: https://habr.com/ru/post/1276454/


All Articles