Convert Javascript current date time to UTC date time in milliseconds - Stack Overflow

I can't see a way to convert the current datetime in Javascript to a full date time in UTC. I nee

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 0
Add a ment  | 

1 Answer 1

Reset to default 4

Per 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744692148a4588272.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信