Search code examples
javascriptjqueryhtmlepoch

Unix Timestamp -> Human readable error


I have followed guides, read many answers on this very website, but I cannot get a unix epoch time to render properly.

This is an example timestamp as taken from the JSON file output.json

"timestamp": "1365427203000",

Here is my code

$.getJSON('output.json', function (data) {

    var myDate = new Date( data.RTPPMDataMsgV1.timestamp *1000);

    var timestamp_information = '<p>';
    timestamp_information += 'Last update : ' + myDate.toGMTString();
    timestamp_information += '</p>';
    // load the content into timestamp_placeholder div
    $("#timestamp_placeholder").html(timestamp_information);

Here is the output..

Last update : Tue, 31 Aug 45238 14:10:00 GMT

When I feed that time stamp number into an online EPOCH convertor, it comes back fine (8th april approx 13:25 GMT)

Can anyone assist? Is it something to do with the epoch being a number string as opposed to an integer?


Solution

  • Thanks to the users who commented.

    Timestamp was already being multiplied by 1000...

    All I did to fix was to use the code above but without the *1000 then I wrapped it in a parseInt so the function new that the info was a number, and not a string of numbers