Sunday, 28 August 2011

How to format a JSON date?

Eval is not necessary. This will work fine:

var date = new Date(parseInt(jsonDate.substr(6)));
The substr function takes out the "\/Date(" part, and the parseInt function gets the integer and ignores the ")\/" at the end. The resulting number is passed into the Date constructor.

Example:
(new Date(parseInt(retrievedEstimate.new_Arrowvisitationdate.substr(6)))).format("MM/dd/yyyy");

this converts /Date(1314014400000)/ to 23/08/2011

ref: http://stackoverflow.com/questions/206384/how-to-format-a-json-date

No comments:

Post a Comment