question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dayjs().isValid() how to use

See original GitHub issue

dayjs() 返回当前系统时间
dayjs().isValid(); 肯定为true
那么传入一个参数呢?
dayjs(‘2018-08-107’).isValid();
dayjs(‘2018-13-01’).isValid();
dayjs(‘1-10-01’).isValid();
结果都是true!

是我打开方式不对吧 “…“

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
kikaendeavorcommented, Aug 24, 2018

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') }

1reaction
kikaendeavorcommented, Aug 24, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found