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

218
Visualizações
Luxon substracting one day if JS date is UTC

I create a date with Luxon in the following way:

const date = DateTime.utc(2000, 6, 23).toFormat('yyyy-MM-dd')

Then I try to convert it to a JS date by doing this:

const jsDate = new Date(date)

Finally, I convert it back to the 'yyyy-MM-dd' format with

const parsedDate = DateTime.fromJSDate(jsDate).toFormat('yyyy-MM-dd')

But instead of giving me 2000-06-23 it gives me 2000-06-22. Is this a bug on Luxon or I need to do something to get the correct date?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I try to convert it to a JS date by doing const jsDate = new Date(date)

Uh, why not just date.toJSDate()?

Instead of giving me 2000-06-23, DateTime.fromJSDate(jsDate).toFormat('yyyy-MM-dd') gives me 2000-06-22. Is this a bug on Luxon or I need to do something to get the correct date?

According to its docs, fromJSDate defaults to creating a DateTime instance in the local (system) timezone. If you expect another UTC date back, you need to specify that:

DateTime.fromJSDate(jsDate, {zone: 'utc'}).toFormat('yyyy-MM-dd')
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