You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Isn't the intention of dayjs.tz.setDefault('America/New_York'); to always return your timezone in the default 'America/New_York'? if so then that seems to be what it is doing.
Isn't the intention of dayjs.tz.setDefault('America/New_York'); to always return your timezone in the default 'America/New_York'? if so then that seems to be what it is doing.
"dayjs.tz.setDefault('America/New_York'); " should be a global setting, but in specific situations, you might want to obtain the time based on other timezones, such as dayjs.tz('2024-12-11T12:37:43.000Z', 'America/Toronto') or dayjs.tz('2024-12-11T12:37:43.000Z', 'Asia/Hong_Kong'). Since the second parameter specifies a different timezone, shouldn't it return the time for that corresponding timezone?
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.tz.setDefault('America/New_York');
const time1 = dayjs.tz('2024-12-11T12:37:43.000Z', 'America/Toronto').format('YYYY-MM-DD HH:mm');
console.log(time1);
const time2 = dayjs.tz('2024-12-11T12:37:43.000Z', 'America/New_York').format('YYYY-MM-DD HH:mm');
console.log(time2);
const time3 = dayjs.tz('2024-12-11T12:37:43.000Z', 'Asia/Hong_Kong').format('YYYY-MM-DD HH:mm');
console.log(time3);
export default dayjs;
Result: time1 = 2024-12-11 12:37
time2 = 2024-12-11 12:37
time3 = 2024-12-11 12:37
"dayjs": "^1.11.13"
Why can't all dates return the correct date based on the timezone?
The text was updated successfully, but these errors were encountered: