Closed illuminati-confirmed closed 12 months ago
Hey! The third argument is not the constructor to use but just the backup date to use when it's not enough information in the input to build a date.
date-fns is built, so the date is always in the local timezone, hence the result.
You actually don't need date-fns for that as Date always parse date strings without timezone in UTC:
But accidentally, you're right. UTCDate
indeed had a problem accepting strings, which I fixed in v1.1.0
:
I am trying to use date-fns to parse a string as if it were a UTC date instead of a local date, yet parsing does not return a UTC date and instead only returns a local date, but minus the timezone offset to pretend it is from UTC.
parse(date, 'yyyy-MM-dd', new UTCDate()); // returns 2023-05-02T14:00:00.000Z for input 2023-05-03
As a unix timestamp this is1683036000 which corresponds to 2023-05-02T14:00:00
which is clearly NOT 2023-05-03 as UTC time.