Kokesh
Kokesh

Reputation: 3263

Get offset from timezone

I have a javascript timestamp and timezone ( "Europe/Stockholm" for example)

How can I get difference from UTC? It can be seconds, or any other time unit.

For example my timezone is UTC-2hrs, so I would get result of 7200sec.

Any ideas?

Upvotes: 0

Views: 1887

Answers (1)

Miguel-F
Miguel-F

Reputation: 13548

Look at the ColdFusion function GetTimeZoneInfo (it supports Daylight Savings Time as well).

Ben Nadel has an excellent write up on this topic - Converting To GMT And From GMT In ColdFusion For Use With HTTP Time Stamps

From that article:

ColdFusion has a couple of methods that allow us to easily work with GMT / HTTP time stamps. For starters, there is the GetTimeZoneInfo() method which gives us our local time offset relative to the UTC time. Outputting GetTimeZoneInfo() on my machine gives us:

enter image description here

The UTCTotalOffset gives us the number of seconds that the machine's time zone is offset from GMT / UTC. The UTCHourOffset and the UTCMinuteOffset are simply different representations of this value. Taking the seconds offset, we can easily convert our local times to GMT time using ColdFusion's DateAdd() function...

That should get you going.

Upvotes: 2

Related Questions