Reputation: 3263
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
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. OutputtingGetTimeZoneInfo()
on my machine gives us:The
UTCTotalOffset
gives us the number of seconds that the machine's time zone is offset from GMT / UTC. TheUTCHourOffset
and theUTCMinuteOffset
are simply different representations of this value. Taking the seconds offset, we can easily convert our local times to GMT time using ColdFusion'sDateAdd()
function...
That should get you going.
Upvotes: 2