Jump to content

Javascript countdown needs fixed time zone!


wilsonf1

Recommended Posts

This is pretty urgent as im counting down to a global event on sunday, yet my javascript reacts to a pc clock and not a time zone, so whe nthe event happens in the UK, the countdown timer will be all over the place round the world - is there anyway i can apply GMT or something to this script so everyone see;s the same values?

/*Author: Robert Hashemian[url="http://www.hashemian.com/"]http://www.hashemian.com/[/url]You can use this code in any manner so long as the author'sname, Web address and this disclaimer is kept intact.********************************************************Usage Sample:<script language="JavaScript">TargetDate = "12/31/2020 5:00 AM";BackColor = "palegreen";ForeColor = "navy";CountActive = true;DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";FinishMessage = "It is finally here!";</script><script language="JavaScript" src="http://www.hashemian.com/js/countdown.js"></script>*/function calcage(secs, num1, num2) {  s = ((Math.floor(secs/num1))%num2).toString();  if (s.length < 2)    s = "0" + s;  return "<b>" + s + "</b>";}function CountBack(secs) {  if (secs < 0) {    document.getElementById("cntdwn").innerHTML = FinishMessage;    return;  }  DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));  document.getElementById("cntdwn").innerHTML = DisplayStr;  if (CountActive)    setTimeout("CountBack(" + (secs-1) + ")", 990);}function putspan(backcolor, forecolor) { document.write("<span id='cntdwn' style='background-color:" + backcolor +                 "; color:" + forecolor + "'></span>");}if (typeof(BackColor)=="undefined")  BackColor = "white";if (typeof(ForeColor)=="undefined")  ForeColor= "black";if (typeof(TargetDate)=="undefined")  TargetDate = "12/31/2020 5:00 AM";if (typeof(DisplayFormat)=="undefined")  DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";if (typeof(CountActive)=="undefined")  CountActive = true;if (typeof(FinishMessage)=="undefined")  FinishMessage = "";putspan(BackColor, ForeColor);var dthen = new Date(TargetDate);var dnow = new Date();ddiff = new Date(dthen-dnow);gsecs = Math.floor(ddiff.valueOf()/1000);CountBack(gsecs);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...