This has been making me nuts all day. I understand that JS Date() will set to local time, and thus, make it appear that it's been bumped one day in the past. However, all formatting with date-fns requires a date object, at least as far as I can tell, and it's just plain frustrating to simply format a date, stored ONLY as a date type in Postgres. I'm an inch away from simply parsing and formatting the correct UTC date myself and ditching date-fns.
Date is stored like so in pg: | 2022-11-08 |
I'm formatting like so, on the front-end: | format(new Date(job.active_range_start), "MMM dd, yyyy") |
The value of job.active_range_start is: |
'2022-11-08T00:00:00.000Z' |
What I get after formatting w/ date-fns: | 'Nov 07, 2022' |
But new Date(job.active_range_start) results in this: |
Mon Nov 07 2022 19:00:00 GMT-0500 (Eastern Standard Time) |
How can I simply use date-fns format()
(or whatever) to format the correct UTC date onto the screen? I tried parse(), parseISO(), parseJSON() and all end up giving me the non-UTC localized datetime.