admin管理员组文章数量:1391951
I can't see a way to convert the current date/time in Javascript to a full date time in UTC. I need an equivalent to
var now = new Date().getTime();
but one that returns the UTC time in milliseconds
some thing like this
var UTCnow = new Date().getUTCTime();
I can't seem to see what I can use to make this happen in the JS Date object.
Any help would be appreciated.
I can't see a way to convert the current date/time in Javascript to a full date time in UTC. I need an equivalent to
var now = new Date().getTime();
but one that returns the UTC time in milliseconds
some thing like this
var UTCnow = new Date().getUTCTime();
I can't seem to see what I can use to make this happen in the JS Date object.
Any help would be appreciated.
Share Improve this question asked Mar 22, 2018 at 23:27 chuckdchuckd 14.7k34 gold badges179 silver badges396 bronze badges 01 Answer
Reset to default 4Per the documentation:
The
getTime()
method returns the numeric value corresponding to the time for the specified date according to universal time.
getTime()
always uses UTC for time representation. For example, a client browser in one timezone,getTime()
will be the same as a client browser in any other timezone.
In other words, it already does what you are asking.
You can also do the same thing without instantiating a Date
object:
var utcnow = Date.now();
Which the docs describe as:
The
Date.now()
method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
本文标签: Convert Javascript current date time to UTC date time in millisecondsStack Overflow
版权声明:本文标题:Convert Javascript current date time to UTC date time in milliseconds - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744692148a2620058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论