AjaxPro JSON Parser and Dates
Because there are a lot of developers using the stand-alone JSON parser (which is included in the release package of AjaxPro) I decided today to serialize the .NET data type System.DateTime with the UniversalSortableDateTimePattern (yyyy'-'MM'-'dd HH':'mm':'ss'Z') as a simple string. You can use this string as input value, too, it will be parsed to an .NET System.DateTime.
Below you will find an example how to use the different JSON outputs in a simple ConsoleApplication:
The output will be similar to this:
"2006-09-22 09:49:18Z"
22.09.2006 09:49:18
22.10.2006 12:00:00
23.07.1977 03:13:49
20.09.2006 12:23:02
Note: when using AjaxPro for ASP.NET web application you will still get the JavaScript Date object.
1 Comment
Comments have been disabled for this content.
Michael Rumpler said
I try again 'cause my first comment still does not appear after 6.5 hours. I am using version 6.10.6.2 of the AjaxPro.dll and AjaxPro.JSON.dll but the result of AjaxPro.JavaScriptSerializer.Serialize(DateTime.Now) is new Date(Date.UTC(2006,9,27,8,59,53,506)) and not the string that you wrote. What I would need is the other direction, but this doesn't work either: AjaxPro.JavaScriptDeserializer.DeserializeFromJson("2006-10-27 10:00:00", typeof(DateTime)) throws an System.NotSupportedException: Specified method is not supported. at AjaxPro.DateTimeConverter.Deserialize(IJavaScriptObject o, Type t) Michael