Search code examples
node.jsdatetimesocrata

Socrata nodejs - convert floating time stamp to a date time format


I am fetching data from an api using socrata : Api Link

There is a field called datetime which is of type floating time stamp. How can I convert this value to datetime format. When I tried with normal time stamp to datetime format conversion, its always gives value similar to this: 1970-01-18T17:38:45.960Z. ie year is always: 1970.

Egs: datetime value: 1532325960

var d = new Date(1532325960);
console.log(d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear());

Is this correct or wrong?


Solution

  • You should pass timestamp value in milli seconds to the Date constructor. This will give you the correct date.

    var d = new Date(1532325960 * 1000);
    console.log(d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear());