Convert UNIX date timestamp to date

0

When the information reaches my API, it arrives with the Unix format TimeStamp

For example: 1535440000 I need to convert this format to YYYY-mm-ddTHH:MM:ssZ eg: 2018-05-31T16:49:27.698Z .

I'm working on JavaScript and MongoDB. Is there a function to carry out this transformation?

Greetings and thanks

    
asked by Manolait 10.09.2018 в 15:34
source

1 answer

2

In javascript you multiply the value by 1000 to get the time in milliseconds and you get with toISOString the date in ISO8601 format.

var data = 1535440000;
var date = new Date(data * 1000).toISOString();
alert(date);

Origin here .

    
answered by 10.09.2018 / 15:43
source