I have a timezone string, for example, "Pacific Time (US & Canada)". I need to get the equivalent of 3pm in that timezone in UTC for particular dates, including daylight savings time. How can I go about this?
For example, I need to find 3pm on December 3rd, PDT in UTC time.
That time zone identifier looks like it came from Rails, or from Twitter (which uses Rails). You first need to convert it to a standard IANA zone identifer such as "America/Los_Angeles". See the
MAPPING declaration in the ActiveSupport::TimeZone docs.
Then you can use one of the libraries I mentioned here.
In particular, you may want to try moment-timezone. You'll need the latest develop version for this particular feature, as it was added in issue #25 which is not yet in the current release. Then you can do something like this:
You can adjust the input/output format to whatever makes sense for you and is supported by moment.js.
The other time zone libraries I mentioned may also offer similar features without as much overhead, so they are worth a look.
This seems to work for me though it does feel a little fragile
new Date('2013-12-03 15:00:00 PDT').toUTCString() -> "Tue, 03 Dec 2013 22:00:00 GMT"
©2020 All rights reserved.