Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!