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

82
Visualizações
Format time only with Luxon

I have a time saved as a string in my database. I'm trying to parse that time using Luxon, and then set various date parts to my various controls. While I'm not getting any errors during the parsing, I'm getting unexpected values.

The time I'm testing with: 12:05 AM America/Chicago

I'm attempting to parse as follows.

const date = DateTime.fromFormat(value, 'hh:mm a z');

The output is

Hour: 1 (incorrect)

Minute: 05 (correct)

Meridien: (AM) (correct)

Timezone: America/New_York (incorrect)

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

0

If you set opts.setZone to true, it will keep the DateTime in Chicago time, so any output will be displayed in that timezone.

To display the time in your local zone you can use DateTime.toLocal().

You can switch zone again by using the DateTime.setZone() function if you need to.

const { DateTime } = luxon;

const value = '12:05 AM America/Chicago';

const date = DateTime.fromFormat(value, 'hh:mm a z', { setZone: true });

console.log('Timezone:', date.toFormat('z'))
console.log('Time (Chicago):', date.toFormat('hh:mm a'))
console.log('Time (local):', date.toLocal().toFormat('hh:mm a'))
console.log('Time (New York):', date.setZone('America/New_York').toFormat('hh:mm a'))
.as-console-wrapper { max-height: 100% !important; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/2.3.1/luxon.min.js" integrity="sha512-Nw0Abk+Ywwk5FzYTxtB70/xJRiCI0S2ORbXI3VBlFpKJ44LM6cW2WxIIolyKEOxOuMI90GIfXdlZRJepu7cczA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

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