dayjs
dayjs copied to clipboard
Parse error when time is before 1000-01-01
trafficstars
Describe the bug
dayjs('0001-01-01').format('YYYY-MM-DD') // 1901-01-01
dayjs('1-01-01').format('YYYY-MM-DD') // 2001-01-01
So who knows how to parse 0001-01-01 or -0001-01-01.
Expected behavior
dayjs('0001-01-01').format('YYYY-MM-DD') // 0001-01-01
Information
- Day.js Version:v1.10.7
- OS: Mac
- Browser: Chrome
- Time zone: GMT+08:00
Confirming this bug
- Node v16.17.0
- DayJS : 1.11.5
You can fix by specifying the time :
> dayjs('0001').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01t').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01t00').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01t00:00').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01t00:00:00').format('YYYY-MM-DD')
'1901-01-01'
> dayjs('0001-01-01t00:00:00z').format('YYYY-MM-DD')
'1-01-01'
> dayjs('0001-01-01z').format('YYYY-MM-DD')
'2001-01-01'
Same error here (v1.11.5, Chrome). Trying to display year 0001 and always getting 1901 instead
It should be able to parse it accordingly (as momentJS does)
dayjs('0001-01-01').format('YYYY-MM-DD') -> 0001-01-01