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

166
Vistas
JavaScript setMinutes() behaves wrongly around DST ending

When the US Daylight Saving ends, we switch our clocks back 1 hour and this makes the 1 AM hour happen twice on that day. However, JavaScript behaves strangely for timestamps in the second 1 AM hour (after clock switch) and keeps reverting them to the daylight time of 1 hour before. This can be seen when trying to use setMinutes and setHours methods.

This code sets the minutes of a date to its current minutes value, and behaves as expected (browser has America/Los_Angeles time zone):

let date = new Date("2021-07-07T09:40:00.000Z");

console.log(date.toLocaleString("en-us", {timeZoneName: "short"}));
// "7/7/2021, 2:40:00 AM PDT"

date.setMinutes(date.getMinutes());

console.log(date.toLocaleString("en-us", {timeZoneName: "short"}));
// "7/7/2021, 2:40:00 AM PDT"

But this code doesn't:

let date = new Date("2021-11-07T09:50:00.000Z"); // DST ended on Nov 7 at 2 AM

console.log(date.toLocaleString("en-us", {timeZoneName: "short"}));
// "11/7/2021, 1:50:00 AM PST"

date.setMinutes(date.getMinutes());

console.log(date.toLocaleString("en-us", {timeZoneName: "short"}));
// "11/7/2021, 1:50:00 AM PDT" <-- Wrong time zone

So the Date object can correctly print timestamps in the second (standard time) hour, but it interprets the date as still in daylight time when using setMinutes().

Is this expected behavior? It seems odd that date.setMinutes(date.getMinutes()) should alter the date.

about 4 years ago · Juan Pablo Isaza
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