views:

84

answers:

4

I'm asking this on behalf of a certain corporation:

http://www.microsoft.com/visualstudio/en-us/watch-it-live

Things to bear in mind:

  • It's 8:30 AM at different times depending on where you are in the world. For example, where I am, it is already 10 AM, whereas in Redmond it's still only 2 AM.

That's probably the main thing, I guess. Can any SO users recommend ways to improve the existing countdown page so that it works correctly for users in any timezone?

(Serious question - clearly this is a pit that is easy to fall into!)

A: 

Initilise two Date objects, one using local time for the client, one using server time (dynamically inserted into the document with whatever server side language you use).

Use those objects to calculate an offset, and use that to modify your countdown.

This also deals with clocks which are set incorrectly as well as users in different timezones.

David Dorward
+1  A: 

You can do it all with Javascript. This should get you going

var d = new Date()
var gmtHours = -d.getTimezoneOffset()/60;
document.write("The local time zone is: GMT " + gmtHours);
DrLazer
A: 

You'd need to us JS - http://msdn.microsoft.com/en-us/library/014ykh71(VS.85).aspx

Jonathan
A: 

Why don't you show the time in GMT format?

But if you want to give User's time zone then get time zone of the pc and calculate difference and put the logic.

<script type="text/javascript" language="javascript">

var tzo=(new Date().gettimezoneOffset()/60)*(-1);

</script>

and you can display the time that you want.

Ravia
A countdown is **far** more engaging then "Here is a time. Convert it to whatever timezone you are in and then work out how long to go it is"
David Dorward