0

Possible Duplicate:
Clock in different time zones

I've been looking everywhere and can't seem to find a simple solution for this.

I'm looking to show multiple timezones say New York, Rio, London, etc. in 24hr mode.

Sort of like this image:

I know this can be done in good old javascript but no idea where to start. I'm most likely gonna be showing more than 3 timezones, so something that is easy to change & customise would be the bomb.

Please help & thank you in advance!

Community
  • 1
  • 1

1 Answers1

0

Create a Date instance. Use setMinutes to set the time based on the difference between the local time zone offset (available using getTimezoneOffset) and the offset of whatever other time zone you wish.

I suggest minutes because the time zone offset it returned as minutes to add to the current time to get UTC. So to get the time for somewhere that is UTC-04:00 (New York):

var d = new Date();
var offset = d.getTimezoneOffset();
var targetOffset = -4*60;
d.setMinutes(d.getMinutes() + offset + targetOffset);

Note that this just sets the time so that methods like getHours, getMinutes, etc. return adjusted values, the date object still has a local time zone offset and may have errors over daylight saving boundaries.

friism
  • 19,068
  • 5
  • 80
  • 116
RobG
  • 142,382
  • 31
  • 172
  • 209
  • Be very careful with this. A "time zone" and a "time zone offset" are two different things. -4 is only the offset in New York for part of the year (during the summer). The rest of the year, the offset is -5. – Matt Johnson-Pint Nov 25 '13 at 20:11