Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

94
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda