dayjs
dayjs copied to clipboard
Setting the timezone changes date's unix time
Describe the bug
It appears that my local time zone's DST affects absolute time of the Dayjs object.
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
dayjs.extend(utc);
dayjs.extend(timezone);
const a = dayjs('2025-10-26T04:00:00.000Z');
const b = dayjs('2025-10-26T04:00:00.000Z').tz('America/New_York');
// getting `false` to all of these comparisons, but I expect them all to be `true`.
console.log(a.valueOf() === b.valueOf());
console.log(a.unix() === b.unix());
console.log(a.toISOString() === b.toISOString());
Information
- Day.js Version: 1.11.18
- Browser: Chrome 141.0.7390.55 (Official Build) (arm64)
- Time zone: UTC +2 CEST (Europe/Warsaw)
Ran into this as well on Day.js 1.11.18 looks like .tz() reinterprets the input as local time, and then .toISOString() recalculates UTC based on the new offset. That causes unexpected shifts around DST (e.g. 04:00Z becomes 05:00Z). Moment.js handles this more predictably, so migrating is tricky. Happy to explore a PR that fixes this.