Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
Date API is changing date when creating a new instance of Date object with parameter in milliseconds

I'm trying to parse epoch time in milliseconds to UTC timestamp. To achieve this I'm doing:

new Date([my variable in milliseconds]).toUTCString()

and this is returning the following:

output

When the correct date should actually be:

correct date

To recreate this you can use this code:

let dateInMills = 1655154491.8357913;
let parsedDate = new Date(1655154491.8357913).toUTCString();

console.log(parsedDate);

The number that I'm passing to the Date object is the exact same number that is being passed during the tests as it is static data.

More proof on the error:

running the code in the browser console

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The Date constructor can take a number as it's parameter. However, this number should be in milliseconds. In your case, you seams to have the time in second. You should multiply your input by 1000.

let dateInMills = 1655154491.8357913;
let parsedDate = new Date(dateInMills * 1000).toUTCString();

console.log(parsedDate);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!