jquery convert number to date? [duplicate]

筅森魡賤 提交于 2019-11-28 06:49:34
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/

Try the below code...

    var myDate = new Date( your epoch date *1000);
    alert(myDate.toGMTString());
    var mytime=myDate.toGMTString()
alert(new Date(1273185387).toUTCString());

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.

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

Convert json date to date format in jQuery

 <script>
  var date = "\/Date(1297246301973)\/";
  var nowDate = new Date(parseInt(date.substr(6)));
  alert(nowDate )
</script>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!