How to implement a countdown clock on a product launch web page?
I'm asking this on behalf of a certain corpora开发者_StackOverflow社区tion:
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!)
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);
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.
You'd need to us JS - http://msdn.microsoft.com/en-us/library/014ykh71(VS.85).aspx
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.
精彩评论