dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

can't parse string without year,month and day like '18:40:44'

Open shlroland opened this issue 4 years ago • 2 comments

Describe the bug

dayjs('18:40:44', 'HH:mm:ss')
// Invalid Date

when I use dayjs from node_modules,it can't parse the string Expected behavior but when I run this code in console of dayjs,I can get the true answer.

dayjs('18:40:44', 'HH:mm:ss')
d {$L: "en", $u: undefined, $d: Tue Dec 08 2020 18:40:44 GMT+0800 (中国标准时间), $y: 2020, $M: 11, …}
$D: 8
$H: 18
$L: "en"
$M: 11
$W: 2
$d: Tue Dec 08 2020 18:40:44 GMT+0800 (中国标准时间) {}
$m: 40
$ms: 0
$s: 44
$u: undefined
$y: 2020
__proto__: Object

Information

  • Day.js 1.9.6
  • OS: Macos
  • Browser Chrome 87
  • Time zone: +8

shlroland avatar Dec 08 '20 13:12 shlroland

https://day.js.org/docs/en/parse/string-format This dependent on CustomParseFormat plugin to work

iamkun avatar Dec 08 '20 13:12 iamkun

You should use

dayjs('10:12', 'HH:mm').isBefore( dayjs('10:13', 'HH:mm') )

iamkun avatar Dec 30 '20 03:12 iamkun