Converting an Epoch Date to a Significant Javascript Date

I get a string value "/Date(1342709595000)/"in JSON. I am trying to extract the numbers alone and convert the epoch date to a ful Javascript Date value in the format mm / dd / yy hh: mm: ss. I was able to complete the first part of the question by extracting the numbers, but I could not convert it today into a human readable format, available at http://www.epochconverter.com/

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

+5
source share
1 answer

There is nothing that you really need to do, they are already milliseconds, since the era and dates of javascript take milliseconds from the era.

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

+15
source

All Articles