{"date":"Thu Dec 06 14:56:01 IST 2012"}
I am getting this string as JSON can I convert it to JS date object?
{"date":"Thu Dec 06 14:56:01 IST 2012"}
I am getting this string as JSON can I convert it to JS date object?
Edit: Unfortunately i was totally wrong, sry for that,my bad, it happened to always result in today, but to not screw you up, heres an solution which should work for you anyway If you get Different Time strings from your Server, maybe the best way is to write a Regex pattern that matches your String patterns
date propertie from your JSON ObjectmyJson.date.replace(" IST","")myDate = new Date("Thu Dec 06 14:56:01 2012")var myJson = {"date":"Thu Dec 06 14:56:01 IST 2012"}
var myDate = new Date(myJson.date.replace(" IST",""))
console.log(myDate.toLocaleDateString())
Heres the JSBin
Date call ). Very interesting.The right way to convert your JSON to the data object it's parsing this date as a string.
var myJson = {"date":"Thu Dec 06 14:56:01 IST 2013"}
var myDate = new Date(Date(myJson.date))
console.log(myDate.getFullYear()) // 2012
Doesn't work with a Year different from the current one.
Related link
Where can I find documentation on formatting a date in JavaScript?