Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding TimeZone to JS Countdown Timer

Status
Not open for further replies.

Kharas

Programmer
Jan 30, 2007
39
0
0
MX
Greetings, I have the following code:

Code:
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!-- //start

// NOTE: the month entered must be one less than current month. ie; 0=January, 11=December
// NOTE: the hour is in 24 hour format. 0=12am, 15=3pm etc
// example: dateFuture = new Date(2003,03,26,14,15,00) = April 26, 2003 - 2:15:00 pm
// format: dateFuture = new Date(year,month-1,day,hour,min,sec)

dateFuture = new Date(2007,7,9,13,5,46);

// TESTING: comment out the line below to print out the "dateFuture" for testing purposes
//document.write(dateFuture +"<br />");


//###################################
//nothing beyond this point
function GetCount()

{

	dateNow = new Date();									//grab current date
	
	if (dateNow.getTime() < dateFuture.getTime())		//Checking if date set for counter has expired
	
	{
	
	//It hasn't expired so we get the counter started
	
	amount = dateFuture.getTime() - dateNow.getTime(); //calc milliseconds between Now and Then
	delete dateNow;
	days=0;hours=0;mins=0;secs=0;out="";

		
		amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

		days=Math.floor(amount/86400);//days
		amount=amount%86400;

		hours=Math.floor(amount/3600);//hours
		amount=amount%3600;

		mins=Math.floor(amount/60);//minutes
		amount=amount%60;

		secs=Math.floor(amount);//seconds

		if(days != 0){out += ((days<10)?"0":"") + days + ":";}
		if(days != 0 || hours != 0){out += ((hours<10)?"0":"") + hours + ":";}
		if(days != 0 || hours != 0 || mins != 0){out += ((mins<10)?"0":"") + mins + ":";}
		out += ((secs<10)?"0":"") + secs + " EST";
		
		document.getElementById('countbox').innerHTML=out;

		setTimeout("GetCount()", 1000);
		
	}
	
	else
	
		{
	
		amount = dateFuture.getTime() - dateNow.getTime();		//calc milliseconds between dates
		amount = Math.floor(amount/1000);//turn the milliseconds into seconds
		amount = Math.floor(amount/60);//turn the seconds into minutes
		delete dateNow;
	
	
			if (amount < 0 && amount > -40)  //Checking if the match is still 'going' (matches take 40 mins in average)
	
				{
	
				document.getElementById('countbox').innerHTML="Match Is Now Live";
	
				}
	
			else
	
				{
	
				document.getElementById('countbox').innerHTML="No Matches Are Currently Scheduled";
	
				}
	
		}
		
		
}



		
		
//-->
</script>

The problem is that its based on the local timezone of whoever loads it. I was wondering if there was some way of enforcing a timezone so every user gets the same countdown to the same "dateFuture".

Thanks in advance
 
Here's a further explanation of what I said above:

The code, taking the conditionals aside, basically uses date() to establish the date to which the countdown will tick to while also checking the user's local time so that a difference between the THEN and the NOW may be obtained, and thus the countdown be properly run.

I have been going in circles here for days, and I've come to the following conclusions:

I could use the functions that rely on the user's local time to calculate the GMT, and then from there I could find the desired timezone TIME that I want.

The problem is that not all users have their computer's clock properly set, let alone their daylight time savings configurated accordingly, so it's best NOT to rely on the user.

That leads us to finding a way to FIXATE the clock upon the EST time regardless of what every human being has in their computer clock.

Unfortunately, here kicks in my lack of experience and I'm forced to ask you guys if you know of any way to get the 'real' GMT date without using each user's local time as a reference.

Thanks yet again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top