Reputation: 30158
I am getting timestamps for estimated bus arrival times from an API as a timestamp / epoch: 1536589019000
. If I go to a website like this I get the appropriate format:
Monday, September 10, 2018 7:16:59 AM
But if I attempt to convert the date in javascript, for example, with momentjs, I get some date far into the future: 50662-08-08 08:03
moment.unix(estimatedArrivalTime).format("YYYY-MM-DD HH:mm")
How do I convert a unix timestamp properly?
Upvotes: 1
Views: 615
Reputation: 18895
You're getting a timestamp in millesconds instead of seconds. Just passing it like so should work: moment(1536589019000).format("YYYY-MM-DD HH:mm")
Upvotes: 0
Reputation: 6904
divide the time by thousand , moment.unix() expects time to be in seconds
moment.unix(1536589019).format("YYYY-MM-DD HH:mm")
Upvotes: 2