Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't all dates return the correct date based on the timezone? #2785

Open
telenconcept opened this issue Dec 11, 2024 · 2 comments
Open

Comments

@telenconcept
Copy link

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?

@siratl
Copy link

siratl commented Dec 13, 2024

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.

@telenconcept
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants