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

Time:08-31

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?

CodePudding user response:

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

  • Related