Clock In Different Time Zones
Solution 1:
currentTime.getTimezoneOffset()
will give you the time difference between Greenwich Mean Time (GMT) and local time, in minutes.
You can use the value to calculate time in required timezone.
Solution 2:
To do this properly, you will need a time zone database, such as one of the ones I listed here.
All of the other answers to this question are making the mistake in thinking that a "time zone" and a "time zone offset" are the same thing. They are not. For example, the time zone for London is Europe/London
, which can have either a +0 or +1 offset depending on what time of year it is. The time zone for New York is America/New_York
, which can have either a -5 or -4 offset based on a completely different set of dates than London.
You might want to look at moment-timezone:
moment().tz("America/New_York").format()
Solution 3:
You can add or subtract hours from your date with
currentTime.setHours(currentTime.getHours()+offset);
where offset is any number of hours.
I updated the jsfiddle with that line and the function so that it accepts a parameter for the offset. This is not the UTC offset, just how many hours to add from the system time. You can get the current UTC offset by currentTime.getTimezoneOffset()/60
Solution 4:
Check out http://www.datejs.com/ it handles dates and timezones nicely
if you check out the demo, in the text box, put 1 GMT
vs 1 MST
or 1 EST
and it will pop out a nice date for you wrt/ that time zone
Solution 5:
Thank you everyone for your help. It was all getting a bit confusing but I found a good example here which is how I ended up working it out. Check out example 4: http://www.ajaxupdates.com/jclock-jquery-clock-plugin/
Hope it's useful for someone else!
Post a Comment for "Clock In Different Time Zones"