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/
Convert from epoch to human-readable dateString date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (epoch*1000)); Epoch in seconds, remove '*1000' for milliseconds. myString := DateTimeToStr(UnixToDateTime(Epoch)); Where Epoch is a signed integer. Replace 1526357743 with epoch.
You can take an epoch time divided by 86400 (seconds in a day) floored and add 719163 (the days up to the year 1970) to pass to it. Awesome, this is as manual as it gets.
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()
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With