CodePark/ questions / Dates & time zones
START PRACTICINGPRACTICE
Frontend question · Internationalization › Dates & time zones

The computer's time zone is America/New_York. Daylight saving time starts at 2:00 on 10 March 2024. What does this print?

const start = new Date(2024, 2, 9, 12, 0); // 9 March 2024, 12:00
const a = new Date(start.getTime() + 24 * 60 * 60 * 1000);
const b = new Date(start);
b.setDate(b.getDate() + 1);
console.log(a.getHours(), b.getHours());
13 12

On 10 March, clocks in New York jump from 2:00 to 3:00, so that day has only 23 hours. Adding exactly 24 hours of milliseconds lands on 13:00. setDate works in local calendar days, so it keeps 12:00.

"
12 12" is the tempting wrong answer. It assumes every day is 24 hours long. Use calendar methods (or Temporal) to add days, and use milliseconds only for exact durations like "in 90 minutes".