Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getDay() function of "date-fns" gives different results for the same date

Given the following 2 dates in ISO format:

2022-08-28T01:00:00.000Z
2022-08-28T23:00:00.000Z

getDay() returns 0 for the first one, and 1 for the second one.

Note that it's the same date, and only time is changed.

I am assuming it returns the result after converting it to local time. Because of that behavior, my logic has some side-effects.

Is there a way to get the result without conversion to local time?

like image 265
NeNaD Avatar asked Oct 16 '25 23:10

NeNaD


1 Answers

The getDay documentation clearly states it returns results in local time. You need the getUTCDay function.

like image 60
Tim Roberts Avatar answered Oct 18 '25 12:10

Tim Roberts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!