`dayjs("2013-11-18T11:55:20").tz("America/Toronto")` does not work
See original GitHub issueDescribe the bug
dayjs("2013-11-18T11:55:20").tz("America/Toronto") (as suggested in the docs) outputs the following:
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(timezone)
console.log(dayjs('2013-11-18T11:55:20').tz('America/Toronto'))
// Output
{
'$L': 'en',
'$d': Invalid Date,
'$x': { '$timezone': 'America/Toronto' },
'$y': NaN,
'$M': NaN,
'$D': NaN,
'$W': NaN,
'$H': NaN,
'$m': NaN,
'$s': NaN,
'$ms': NaN,
'$offset': NaN,
'$u': false
}
Expected behavior
The following should be the output:
{
'$L': 'en',
'$d': 2013-11-18T10:55:20.000Z,
'$x': { '$localOffset': -60, '$timezone': 'America/Toronto' },
'$y': 2013,
'$M': 10,
'$D': 18,
'$W': 1,
'$H': 11,
'$m': 55,
'$s': 20,
'$ms': 0,
'$offset': -300
}
Information
- Day.js Version:
1.11.6,1.11.0,1.10.0,1.9.0(it seems like the bug is in all versions sinceutcplugin was introduced) - OS: [e.g. iOS]: Arch Linux
- Browser [e.g. chrome 62]: n/a
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]: tested with
America/TorontoandEurope/Slovakia; I don’t think it matters; - Node version:
19.0.0 - NPM version:
8.19.2
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:11 (4 by maintainers)
Top Results From Across the Web
`dayjs.tz()` is not building dates with correct timezone for many ...
The issue is that the function is not converting correctly between timezones. Simplest case to see is when converting to the same timezone...
Read more >Time Zone
Day.js supports time zone via the Internationalization API in supported environments. By using the native API, no extra bytes of timezone data need...
Read more >dayjs timeZone is not supported - react native - Stack Overflow
I have tried to update the dayjs package,the intl-react package and intl package itself, couldn't found any solution to this problem with react ......
Read more >Working with Dates and Times with Day.js
To learn more about JavaScript dates, kindly visit this link. Formatting dates. Get the formatted date using the token string that was supplied....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The issue is known and tracked there:
NodeJS fix: https://github.com/nodejs/node/pull/45573
The problem appears to be here: https://github.com/iamkun/dayjs/blob/9c20e77caf7b1b5eccf418175203b198d4e29535/src/plugin/timezone/index.js#L98-L99
The offset is calculated by converting a Date to an en-US locale string, then back again to a Date. However, the conversion back fails in some environments:
This may depend on obscure details of the OS you’re running on.
For some other locales this works without issue: