dayjs().isValid() how to use
See original GitHub issuedayjs() 返回当前系统时间
dayjs().isValid(); 肯定为true
那么传入一个参数呢?
dayjs(‘2018-08-107’).isValid();
dayjs(‘2018-13-01’).isValid();
dayjs(‘1-10-01’).isValid();
结果都是true!
是我打开方式不对吧 “…“
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
Validation
Returns a boolean indicating whether the Dayjs 's date is valid. Non-strict check. Only checks if the value could be parsed to a...
Read more >DayJS isValid behaves differently to Moment - Stack Overflow
August 2021: It's now possible to detect with .isValid() method these invalid dates passing a third parameter as true to dayjs constructor:
Read more >Validation .isValid() doesn't work always · Issue #320 - GitHub
I'm just swapping over from Moment to DayJS. The unit tests I have in place to validate incorrect entries like 2000-02-31 by using...
Read more >Parse, Validate, Manipulate, and Display Dates and Times in ...
Validating Dates and Times. Once you've parsed a date and time with Day.js you can leverage the isValid() method to determine if what...
Read more >Working with Dates and Times with Day.js
You can use the JavaScript date method, toISOString(), which returns the freshly formed date in ISO format, to confirm this. new Date().
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

Actually,
new Date(2018,13,01) => 2019-01-31T16:00:00.000Z
new Date(‘2018-08-107’) => Invalid Date
new Date(‘1-10-01’) => Invalid Date
But
dayjs(‘2018-13-01’).isValid(); => true
dayjs(‘2018-08-107’).isValid(); => true
dayjs(‘1-10-01’).isValid(); => true
so, there must be something wrong with the isValid function.
isValid() { return !(this.$d.toString() === 'Invalid Date') }@xxyuk
woooh~~~~
the result is different between chrome and firefox.
firefox doesn’t support string like ‘1-10-01’, but new Date(1,10,01) is ok.
format like (yyyy, mm-1, dd, hh, mm, ss) or (mm/dd/yyyy hh:mm:ss) are much more compatible.