[英]getDay() function of "date-fns" gives different results for the same date
Given the following 2 dates in ISO format:给定以下 2 个 ISO 格式的日期:
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. getDay()
第一个返回0
,第二个返回1
。
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?有没有办法在不转换为本地时间的情况下获得结果?
The getDay
documentation clearly states it returns results in local time. getDay
文档清楚地说明它以当地时间返回结果。 You need the getUTCDay
function.您需要
getUTCDay
function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.