jquery convert number to date? [duplicate]
i have a json file that returns "date_created":"1273185387"
in epoch format
i want to convert it to something like this Thu, 06 May 2010 22:36:27 GMT
any script to do this conversion?
var myObj = $.parseJSON('{"date_created":"1273185387"}'),
myDate = new Date(1000*myObj.date_created);
console.log(myDate.toString());
console.log(myDate.toLocaleString());
console.log(myDate.toUTCString());
http://jsfiddle.net/mattball/8gvkk/
alert(new Date(1273185387).toUTCString());
Try the below code...
var myDate = new Date( your epoch date *1000);
alert(myDate.toGMTString());
var mytime=myDate.toGMTString()
jQuery doesn't have anything for it, but that's okay, because JavaScript does. The Date
constructor accepts a milliseconds-since-the-Epoch value, so in your case (since that looks like a seconds value) it would be:
var dt = new Date(obj.date_created * 1000);
...where obj
is the result of deserializing that JSON string.
Details in Section 15.9.3.2 of the specification. Alternately, the MDC page is useful.
Convert json date to date format in jQuery
<script>
var date = "\/Date(1297246301973)\/";
var nowDate = new Date(parseInt(date.substr(6)));
alert(nowDate )
</script>
http://jsfiddle.net/y3Syc/1/
var data = {"date_created":"1273185387"};
var date = new Date(parseInt(data.date_created, 10) * 1000);
// example representations
alert(date);
alert(date.toLocaleString());
精彩评论