javascript - Getting incorrect dates converting timestamp with new Date -


i'm trying convert timestamp date i'm getting incorrect dates. i'm working on project angular , typescript.

i have timestamps like: 1451642400 (1st january 2016) , 1454320800 (1st february 2016)

if code:

date = new date(1451642400); console.log(date.tolocalestring()); date = new date(1454320800); console.log(date.tolocalestring()); 

i get: 17/1/1970 20:14:02 , 17/1/1970 20:58:40

when should get: 1/1/2016 10:00:00 , 1/2/2016 10:00:00

what's problem? how can fix it?

you need multiply unix timestamp 1000 in milliseconds.. if this, work:

    date = new date(1451642400 * 1000);      console.log(date.tolocalestring());      date = new date(1454320800 * 1000);      console.log(date.tolocalestring());


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -