Skip to content

parse day off by one #2504

Answered by fturmel
rhufsky asked this question in Q&A
Jun 6, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

The input is treated as being in the system's local time zone, not as UTC.

When you console.log a Date object in Node, it stringifies it using .toISOString() which is a UTC interpretation of the date. So, if you are in a time zone with a positive offset related to UTC, any midnight local date will be represented as the previous day in UTC.

If you really meant that input to be UTC, you could use the X token and add a Z in the date string.

// Note: These are outputs from an eastern time zone system

// same as: new Date(1960, 8, 24)
let d = parse('1960-09-24', 'yyyy-MM-dd', new Date());
console.log(d.toString()); // Sat Sep 24 1960 00:00:00 GMT-0400 (Eastern Daylight Time)
console.log(d.toI…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rhufsky
Comment options

Answer selected by fturmel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants