最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Convert Epoch Date to meaningful Javascript date - Stack Overflow

programmeradmin12浏览0评论

I am getting a string value "/Date(1342709595000)/"in the JSON. I am trying to extract the digits alone and convert the epoch date to meaning ful Javascript Date in the format mm/dd/yy hh:mm:ss . I was able to achieve the first part of the question extracting the digits but couldnot convert it to date object human readable format as available in /

JS Fiddle: /

I am getting a string value "/Date(1342709595000)/"in the JSON. I am trying to extract the digits alone and convert the epoch date to meaning ful Javascript Date in the format mm/dd/yy hh:mm:ss . I was able to achieve the first part of the question extracting the digits but couldnot convert it to date object human readable format as available in http://www.epochconverter.com/

JS Fiddle: http://jsfiddle.net/meetravi/QzKwE/3/

Share Improve this question asked Jul 19, 2012 at 16:47 RaviRavi 3,2005 gold badges27 silver badges36 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 16

There is nothing you really need to do, they are already milliseconds since epoch and javascript dates take milliseconds since epoch.

http://jsfiddle.net/QzKwE/9/

var dateVal ="/Date(1342709595000)/";
var date = new Date(parseFloat(dateVal.substr(6)));
document.write( 
    (date.getMonth() + 1) + "/" +
    date.getDate() + "/" +
    date.getFullYear() + " " +
    date.getHours() + ":" +
    date.getMinutes() + ":" +
    date.getSeconds()
);

发布评论

评论列表(0)

  1. 暂无评论