简体   繁体   中英

How to convert time with a timezone to UTC in javascript

I want to write a method in javascript that takes a date and time zone and then returns a new date thats in UTC.

For example if I give it

Date: 2016/06/21 16:00:00
Time zone: America/NewYork

I should get back

Date: 2016/06/21 20:00:00

I looked at moment js, but seems like they didn't have a utc timezone name.

Please try

moment.tz("2016-06-21 16:00:00", "America/New_York").utc().format();

It gives desired output

refer this for details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM