0

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?

Kokesh
  • 3,165
  • 7
  • 29
  • 46
  • In CF or javascript. If you mean CF, AFAIK there is nothing built in. However, a five second search on "ColdFusion Timezone" turned up [this thread](http://stackoverflow.com/a/795651/104223). Take a look at the [TimeZone CFC](http://www.sustainablegis.com/projects/tz/testTZCFC.cfm). If memory serves, it contains methods that can do what you are asking. – Leigh Jan 15 '14 at 11:19
  • the CFC is really nice. I've just realized, that I'll have probably problem with DST. Maybe I can use JS for the calculation. – Kokesh Jan 15 '14 at 11:29
  • (Edit) Yes, the SO archives are full of great stuff. So it is always good to do a quick search before posting ;-) Out of curiosity, how are you ultimately using the end result? (Just wondering if there are other client/server issues to consider). Maybe you could update the question with more details? – Leigh Jan 15 '14 at 11:36
  • I've realized, that it is enough to do that thing in Javascript, so I've used timezonejs library. It did the trick. Thanks to all! – Kokesh Jan 23 '14 at 09:14

1 Answers1

2

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.

Community
  • 1
  • 1
Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • I could be wrong, but my take on it was they were trying to determine the offset from an arbitrary date/time value, not just the server's date. – Leigh Jan 15 '14 at 16:02
  • I am honestly not sure. The question mentions a client side date, but yet is tagged with CF, suggesting server side dates... {shrug}. @Kokesh - Can you clarify? – Leigh Jan 15 '14 at 16:17
  • As an aside, I wouldn't rely on the built in CF functions due to them not taking into account that Cuba changed it's DST on the 24th rather than 8th... use JODA time and rebuild it everytime there is a new timezone info release. – Jarede Jan 16 '14 at 09:26