dayjs() 返回当前系统时间
dayjs().isValid(); 肯定为true
那么传入一个参数呢?
dayjs(‘2018-08-107’).isValid();
dayjs(‘2018-13-01’).isValid();
dayjs(‘1-10-01’).isValid();
结果都是true!
是我打开方式不对吧 “...“
It's a bit weird... If one inputs 2018-13-01 the dayjs object will be 2019-01-01...
@rfoel
Javascript did the same.
new Date(2018, 13 , 01) => valid date
@rfoel:
Because in its inner code, it just calls something like new Data():
Example:new Date(2018,13,01) => 2019-01-01
isValid is just from this:https://github.com/iamkun/dayjs/blob/002b69520415e0005117db51c9ef5aecc0ed8741/src/index.js#L91
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')
}
@kikaendeavor
new Date('1-10-01') => Wed Jan 10 2001 00:00:00
@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.
Most helpful comment
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') }