D
D
Dmitry Eremin2016-05-06 08:29:12
JavaScript
Dmitry Eremin, 2016-05-06 08:29:12

How to correctly convert a date from UTC to human readable form?

The story is that I get the date: 1462518000
If I slip it into any online converter, we get something like Fri, 06 May 2016 07:00:00 GMT
I write: I get: 1970-Jan-18 04:15:18 Question: why not the correct date?
<p>{{row.dt | date:'yyyy-MMM-dd HH:mm:ss'}}</p>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2016-05-06
@EreminD

Because unixtime is in seconds, and Date in JS is in milliseconds. Multiply by 1000.

> new Date(1462518000 * 1000)
Fri May 06 2016 10:00:00 GMT+0300 (MSK)

UPD: by the way, this is not UTC, but unix timestamp.

D
Dmitry Arushanov, 2016-05-13
@daruwanov

You can look towards the moment js library. Pretty comfortable, pretty simple. There is support for timezone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question