Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

81
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda