When I create a new object var date = new Date(1550571050)
this returns
Mon Jan 19 1970 05:42:51 GMT+0700
while it should be
Mon Feb 19 2019 05:42:51 GTM+0700
whats wrong with it?
When I create a new object var date = new Date(1550571050)
this returns
Mon Jan 19 1970 05:42:51 GMT+0700
while it should be
Mon Feb 19 2019 05:42:51 GTM+0700
whats wrong with it?
var date = new Date(1550571050)
has date 1550571050
which is in seconds.
As described on MDN, Date
constructor accepts a unix timestamp which is
an integer value representing the number of milliseconds
If you add 000 to your date it will be in milliseconds instead of seconds and the date object will be correct
new Date(1550571050000)
// Tue Feb 19 2019 12:10:50 GMT+0200 (Eastern European Standard Time)
Just do like this:
var timestamp = 1550571050;
var date = new Date(timestamp * 1000);
And refer this:
timestamps are in milliseconds so multiply by 1000. then it will give correct date.
new Date(1550571050000)