There are two strange things:
- day 30 instead of 31?
it set 13 as time instead of 00?
new Date('Dec 31, 2019').toISOString() // '2019-12-30T13:00:00.000Z'
Basically what I'm trying to do is to convert original data format into YYYY-MM-DD
.
There are two strange things:
it set 13 as time instead of 00?
new Date('Dec 31, 2019').toISOString()
// '2019-12-30T13:00:00.000Z'
Basically what I'm trying to do is to convert original data format into YYYY-MM-DD
.
new Date('Dec 31, 2019')
- this date will be shown in your local time format.
e.g.:
`Tue Dec 31 2019 00:00:00 GMT+1100` (Your Standard Time)
However, new Date('Dec 31, 2019').toISOString()
- this date will be shown like
2019-12-30T13:00:00.000Z
. It means Dec 31, 2019 minus 11 hours(your time zone).
In addition, to avoid strange behaviors, try to set explicitly year, month and day to avoid strange behavior.
You should parse Date
in the following format:
// yyyy-mm-dd format
// new Date(year, month [, day [, hours[, minutes[, seconds[, ms]]]]])
let yourDate = new Date(parts[0], parts[1]-1, parts[2]); // Be careful: months are 0-based