Javascript 日期时间转换
Javascript DateTime Conversion
我确定这个话题已经被打得一塌糊涂,但我还没有找到解决方案。我使用的库 (fullcalendar) 在您将日期和时间显示在屏幕上后会更改它们的格式。如果您使用 eventClick
函数和 log
事件的开始或结束,对象看起来像这样
Thu Jul 23 2020 23:59:00 GMT-0500 (Central Daylight Time)
现在我想在单击事件后在模态中使用它。在此功能期间,我需要 运行 对日期和时间进行一些检查,因此我使用 JSON.stringify()
.
完成上述操作后,我的日期现在是这样的(注意错误的日期和时间)
"2020-07-24T04:59:00.000Z"
有没有解决这个问题的非“hacky”方法?
时间没有错 - 第一个是 GMT-5,第二个是 UTC。
当你 JSON.Stringify 时,你会得到标准的 UTC 日期,但是 fullcalendar 会为你做一些巧妙的时区处理:
来自the docs:
It’s important to always remember that a Date object is merely a wrapper around a millisecond time since the Unix Epoch (Jan 1, 1970 UTC). The accessor methods on the Date object interpret this millisecond time differently for different time zones, but the underlying millisecond time will remain the same.
您应该使用该图书馆提供给您的方法来获取检查信息。
我确定这个话题已经被打得一塌糊涂,但我还没有找到解决方案。我使用的库 (fullcalendar) 在您将日期和时间显示在屏幕上后会更改它们的格式。如果您使用 eventClick
函数和 log
事件的开始或结束,对象看起来像这样
Thu Jul 23 2020 23:59:00 GMT-0500 (Central Daylight Time)
现在我想在单击事件后在模态中使用它。在此功能期间,我需要 运行 对日期和时间进行一些检查,因此我使用 JSON.stringify()
.
完成上述操作后,我的日期现在是这样的(注意错误的日期和时间)
"2020-07-24T04:59:00.000Z"
有没有解决这个问题的非“hacky”方法?
时间没有错 - 第一个是 GMT-5,第二个是 UTC。
当你 JSON.Stringify 时,你会得到标准的 UTC 日期,但是 fullcalendar 会为你做一些巧妙的时区处理:
来自the docs:
It’s important to always remember that a Date object is merely a wrapper around a millisecond time since the Unix Epoch (Jan 1, 1970 UTC). The accessor methods on the Date object interpret this millisecond time differently for different time zones, but the underlying millisecond time will remain the same.
您应该使用该图书馆提供给您的方法来获取检查信息。