Convert integer to Date in node.js

I am trying to convert an integer to Date using node.js and Date.

I know this is a very common question, but all the solutions that were published earlier did not help me.

I get dates from a json file found at http://api.guardian.gg/chart/elo/4611686018432537994 ,

Example: 1461110400000

What I tried:

    var date = String(new Date(elodata.x));

and

    var date = String(new Date(parseInt(elodata.x)));

But as a result, I get an invalid date.

I understand that this may not be feasible because I do not know how guardian.gg handles this data. But you never know.

+4
source share
2 answers

Date Javascript, (, , :

var date = new Date(elodata.x);

, setTime() Javascript, ,

var date = new Date();
d.setTime(elodata.x);

var d1 = new Date(1461110400000);
console.log(`Constructor: ${d1}`);

var d2 = new Date();
d2.setTime(1461110400000);
console.log(`setTime(): ${d2}`);
Hide result
+3

Date, , . , 1461110400000 , .

, . , , , :

var timeValue = '1461110400000';
console.log( new Date(+timeValue));
Hide result

Number(timeValue) parseInt(timeValue), + .

+1

Source: https://habr.com/ru/post/1669495/


All Articles