ASP.Net’s JSON serialize encodes DateTime instance as a string. If you return a JSON from a MVC contoller, you will notice your data encoded in the form:
This is basically nothing but Jan 16 2011 10:33:29! Ext JS components like data grid, datepicker do not consume this format and needs to be transformed.
Why does Microsoft serialize DateTime in this form?
- To express the data as string
- To express it in numerical form.
The numeric form would be the the number of milliseconds in Universal Coordinated Time (UTC) since epoch. But in either form, we still have the issue of not being able to identify it as date / time. In order to overcome this, MS came up with encoding DateTime values as string in the form:
How to fix it in Ext JS?
Deserializing in Ext JS can be done with the help of Date class. You can use the parseDate static method to convert the serialized date into Date object.
1 2 var dt = Date.parseDate(date,'M$'); dt.format('d/m/y');
The deserialized dates can be displayed in any desired format in your Ext JS scripts! :)