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

118
Vistas
two different dates are returned in momentjs timezone for same set time?

Even the value I set for the time in the moment.js timezones same following two different approaches the value of the date returned is different

  1. moment("02:00","HH:mm").tz('America/Chicago').format()

returns 2022-03-31T15:30:00-05:00

  1. moment().tz('America/Chicago').set({hour:"02",minute:"00"})

returns 2022-04-01T02:00:02-05:00

Can anyone please help me in understanding why is it so?

console.log(moment("02:00","HH:mm").tz('America/Chicago').format());
console.log(moment().tz('America/Chicago').set({hour:"02",minute:"00"}).format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.34/moment-timezone-with-data-10-year-range.js"></script>

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

0

You have different approach with two examples:

In first example you do:

  1. Take local date (2021-04-01 12:15)
  2. Set time for local date to 02:00 (2021-04-01 02:00)
  3. Move that particular local date to other time zone (so e.g. from +02:00 tz to -05:00 - moves back by 7 hours) (2021-03-31 15:00)

While in second example you do:

  1. Take local date (2021-04-01 12:15)
  2. Move that local date to other time zone (2021-04-01 06:15)
  3. Set time for moved time to 02:00 (2021-04-01 02:00)
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