使用时区转换日期为UTC?
一个快速的问题。我有一个ISO字符串日期:
2022-07-03T10:51:09+02:00
您可以看到的这个日期包括时区(+02:00)。
问题:如何将其转换为utc
日期?使用Eg date-fns
或moment
?
编辑:我应该只是将“ 02:00”小时添加到当前日期?因此,它将是12:51:09
?
A quick question. I have a ISO string date:
2022-07-03T10:51:09+02:00
this date as you can see has timezone included (+02:00).
Question: How to convert it into UTC
date? Using e.g. date-fns
or moment
?
Edit: Should I just simply add "02:00" hours to current date? So it would be 12:51:09
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
trivlively noreferrer“>
new Date(IsoString)。 toisostring()
,无需库。Trivially
new Date(isoString).toISOString()
, no libraries required.在我看来,时区只是在不同地理位置上的同一时间戳的表示(由于Unix时间0到处都是相同的秒数,因此经过的秒数不超过)。因此,请小心从现有时间戳手动添加/删除时间。
您可以使用
moment.js
这样做:In my view, timezone is simply the representation of the same timestamp across different geographies (no. of seconds elapsed since unix time 0 is the same everywhere). So be careful while adding/removing time manually from the existing timestamp.
You can do that using
moment.js
like this: