Skip to content
Advertisement

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?

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement