When I fetch data from my PostgreSQL database, it comes in the following format: 2022-11-30T21:00:00.000Z
and it’s not a string; it’s in the form of a date object.
The library that I’m using to work with dates is dayjs
. So here is the issue.
When I call the format method, I get a bad date. like one day off.
dayjs(‘2022-11-30T21:00:00.000Z’) and it gives me 2022-12-01T00:00:00+03:00
.So the real date that was stored was 30th November, but it gives me 1st December.
I saw this post dayjs returns wrong date with format in Stack overflow but the accepted solution is wired because it assumes that I manually remove the Z
at the end.
And even when i try to convert it in a YYYY-MM-DD
by using dayjs('2022-11-30T21:00:00.000Z').format('YYYY-MM-DD')
it’s returning 2020-12-01
.
I really stuck.