addMonths fns 没有返回正确的 UTC 时间
addMonths fns is not returning correct UTC time
我目前居住在 Central European Standard Time
,我希望将所有日期发送到服务器并转换回 UTC
。
我试过简单地使用 date-fns
库中的 addMonths
:
import addMonths from "date-fns/addMonths";
const now = new Date();
// Sat Mar 05 2022 13:56:04 GMT+0100 (Central European Standard Time)
console.log(now);
const oneMonthFromNow = addMonths(now, 1);
// 2022-04-05T11:56:04.189Z
console.log(oneMonthFromNow.toISOString());
CEST
和UTC
只相差一个小时。我预计 now
和 oneMonthFromNOw
之间会有一个小时零一个月的差异,但最终会有一个月零两个小时的差异。
我的期望:
import addMonths from "date-fns/addMonths";
const now = new Date();
// Sat Mar 05 2022 13:56:04 GMT+0100 (Central European Standard Time)
console.log(now);
const oneMonthFromNow = addMonths(now, 1);
// Since CEST time is 13:56:04 I would expect to get 12:56:04 (1 hour difference only)
// But I end up getting 2022-04-05T12:56:04.189Z
console.log(oneMonthFromNow.toISOString());
我是不是误解了什么? now
和 oneMonthFromNow
不应该相差一个月零一小时吗?
The difference between CEST and UTC is simply one hour.
相差两个小时:欧洲中部夏令时(CEST,UTC+02:00)。
您从 2022 年 3 月 5 日的 CET 时间(提前一小时)转到 2022-04-05 的 CEST 夏令时(提前两小时)。
Central European Time (CET) is a standard time which is 1 hour ahead
of Coordinated Universal Time (UTC).
As of 2011, all member states of the European Union observe summer
time (daylight saving time), from the last Sunday in March to the last
Sunday in October. States within the CET area switch to Central
European Summer Time (CEST, UTC+02:00) for the summer.
我目前居住在 Central European Standard Time
,我希望将所有日期发送到服务器并转换回 UTC
。
我试过简单地使用 date-fns
库中的 addMonths
:
import addMonths from "date-fns/addMonths";
const now = new Date();
// Sat Mar 05 2022 13:56:04 GMT+0100 (Central European Standard Time)
console.log(now);
const oneMonthFromNow = addMonths(now, 1);
// 2022-04-05T11:56:04.189Z
console.log(oneMonthFromNow.toISOString());
CEST
和UTC
只相差一个小时。我预计 now
和 oneMonthFromNOw
之间会有一个小时零一个月的差异,但最终会有一个月零两个小时的差异。
我的期望:
import addMonths from "date-fns/addMonths";
const now = new Date();
// Sat Mar 05 2022 13:56:04 GMT+0100 (Central European Standard Time)
console.log(now);
const oneMonthFromNow = addMonths(now, 1);
// Since CEST time is 13:56:04 I would expect to get 12:56:04 (1 hour difference only)
// But I end up getting 2022-04-05T12:56:04.189Z
console.log(oneMonthFromNow.toISOString());
我是不是误解了什么? now
和 oneMonthFromNow
不应该相差一个月零一小时吗?
The difference between CEST and UTC is simply one hour.
相差两个小时:欧洲中部夏令时(CEST,UTC+02:00)。
您从 2022 年 3 月 5 日的 CET 时间(提前一小时)转到 2022-04-05 的 CEST 夏令时(提前两小时)。
Central European Time (CET) is a standard time which is 1 hour ahead of Coordinated Universal Time (UTC).
As of 2011, all member states of the European Union observe summer time (daylight saving time), from the last Sunday in March to the last Sunday in October. States within the CET area switch to Central European Summer Time (CEST, UTC+02:00) for the summer.