developer747
developer747

Reputation: 15928

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.

Upvotes: 0

Views: 1053

Answers (1)

Rohit Shedage
Rohit Shedage

Reputation: 25840

Please try

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

It gives desired output

refer this for details

Upvotes: 3

Related Questions