wilsonf1 Posted March 15, 2007 Share Posted March 15, 2007 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 More sharing options...
jesh Posted March 15, 2007 Share Posted March 15, 2007 Check out getUTCDate():http://www.w3schools.com/jsref/jsref_getUTCDate.asp Link to comment Share on other sites More sharing options...
pulpfiction Posted March 15, 2007 Share Posted March 15, 2007 The getTimezoneOffset() method returns the difference in minutes between local time and Greenwich Mean Time (GMT). So you can manipulate the time based on that and calculate the time difference....http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp Link to comment Share on other sites More sharing options...
jesh Posted March 15, 2007 Share Posted March 15, 2007 Also, I meant to say "check out UTC(): http://www.w3schools.com/jsref/jsref_utc.asp" var date = UTC(); // date is in UTC (who cares about timezone!) Link to comment Share on other sites More sharing options...
wilsonf1 Posted March 15, 2007 Author Share Posted March 15, 2007 hmmm im not too sure which direction to go, W3 never really elaborates does it??? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now