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

280
Vistas
Moment js handle zulu date time

I have problem retriving data from an api and display it in local time.

API print to me zulu datetime 2021-11-12T14:30:29.000000Z I've tried varius soluton to transform it to Europe/Rome gtm but anyone worked, considering olso DST..

moment(d.acktime, "YYYYMMDDHHmmss").utcOffset('Europe/Rome').format("HH:mm");

moment(d.acktime, "YYYYMMDDHHmmss").tz("Europe/Rome").format("HH:mm");

The data displayed is always the zulu tume coming form api.. any ideas??

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Moment will parse an ISO 8601 without specifying a format:

When creating a moment from a string, we first check if the string matches known ISO 8601 formats, we then check if the string matches the RFC 2822 Date time format before dropping to the fall back of new Date(string) if a known format is not found.

Just make sure you use the moment-timezone (with data) library.

const d = { acktime: '2021-11-12T14:30:29.000000Z' };

const formatted = moment(d.acktime).tz('Europe/Rome').format('HH:mm');

console.log(formatted); // 15:30 (Rome is GMT+1)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.34/moment-timezone-with-data.min.js"></script>

Moment is EOL, so I recommend Luxon as an alternative. It is created by the same developers. Setting the timezone is also easier and does not require additional plugins and libraries. See "Time zones and offsets" for more information.

const { DateTime } = luxon;

const d = { acktime: '2021-11-12T14:30:29.000000Z' };

const formatted = DateTime.fromISO(d.acktime).setZone('Europe/Rome').toFormat('HH:mm');

console.log(formatted); // 15:30 (Rome is GMT+1)
<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/2.1.1/luxon.min.js"></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