Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  24] [ 4]  / answers: 1 / hits: 17727  / 3 Years ago, tue, march 9, 2021, 12:00:00

I tried to use the luxon library to move away from moment - to translate the 1615065599.426264 timestamp into an ISO date.


According to the Online Epoch Converter this corresponds to



GMT: Saturday, March 6, 2021 9:19:59.426 PM

Your time zone: Saturday, March 6, 2021 10:19:59.426 PM GMT+01:00

Relative: 3 days ago



Removing the decimal part gives the same result.


The code using luxon:




let timestamp = 1615065599.426264
console.log(luxon.DateTime.fromMillis(Math.trunc(timestamp)).toISO())
console.log(luxon.DateTime.fromMillis(timestamp).toISO())

<script src=https://moment.github.io/luxon/global/luxon.min.js></script>




This result is


1970-01-19T17:37:45.599+01:00
1970-01-19T17:37:45.599+01:00

It is suspiciously close to Unix Epoch (1970-01-01 00:00:00).


Where is my mistake?


More From » date

 Answers
12

So called "Unix time" counts the number of seconds since 01.01.1970 whereas Luxon (and most things JavaScript) expects a value with a millisecond resolution.


Multiplying your value by 1000 will yield the expected result:


> let timestamp = 1615065599.426264
undefined
> new Date(timestamp).toJSON()
'1970-01-19T16:37:45.599Z'
> new Date(timestamp * 1000).toJSON()
'2021-03-06T21:19:59.426Z'

[#50360] Thursday, February 18, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryderalfonsos

Total Points: 655
Total Questions: 88
Total Answers: 91

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
ryderalfonsos questions
Mon, Sep 9, 19, 00:00, 5 Years ago
Wed, Feb 13, 19, 00:00, 5 Years ago
Tue, Feb 12, 19, 00:00, 5 Years ago
Fri, Dec 28, 18, 00:00, 6 Years ago
;