开发者

jquery convert number to date? [duplicate]

开发者 https://www.devze.com 2023-02-26 21:06 出处:网络
This question already has answers here: Convert UTC Epoch to local date 开发者_运维问答(16 answers)
This question already has answers here: Convert UTC Epoch to local date 开发者_运维问答 (16 answers) Closed 3 years ago.

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());
0

精彩评论

暂无评论...
验证码 换一张
取 消