JSON date to Date object – javascript

While working with web services or API with json return, we will get date values in different format, we can’t use this as is where required.

To convert to date object we need to extract integer value and then pass to Date object, below example shows how to get valid date object.

[javascript]
var json = “/Date(-1827639000000)/”
var mytime = new Date(parseInt(json.replace(“/Date(“, “”).replace(“)/”,””), 10));
alert(mytime);
alert(mytime.toUTCString());

[/javascript]

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *