如何在JS中创建UTC日期? [英] How to create UTC date in JS?
本文介绍了如何在JS中创建UTC日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试在UTC中创建日期,如 new Date(Date.UTC(2013,10,7,10,3,19))
时,我仍然收到 2013年11月7日星期四12:03:19 GMT + 0200(FLE标准时间)
,该时间会增加+2小时。如何仅创建 2013-11-07 10:03:19
吗?
When i try to create the date in UTC like new Date(Date.UTC(2013, 10, 7, 10, 3, 19))
i still receive Thu Nov 07 2013 12:03:19 GMT+0200 (FLE Standard Time)
where it adds +2 hours. How to create just 2013-11-07 10:03:19
?
推荐答案
您创建的日期实际上是UTC 2013-11-07 10:03:19,但是当您打印时,它将在您当地的时区中打印日期。要提取UTC日期,可以尝试使用toUTCString(),如下所示:
The date you created is actually 2013-11-07 10:03:19 UTC, but when you print it, it will print the date in your local timezone. To extract the UTC date, you could try using toUTCString(), like so:
Date(Date.UTC(2013, 10, 7, 10, 3, 19)).toUTCString() //"Thu, 07 Nov 2013 10:03:19 GMT"
这篇关于如何在JS中创建UTC日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文