Jump to content


Photo

countdown timer help


  • Please log in to reply
4 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 15 July 2006 - 01:56 AM

hey guys,

I've been trying to make a countdown timer to a specific time for everyday but so far I've been unsucessful, all I was able to accomplish is making a normal timer.

I need a script that can count down how much time there's left before it's 9pm and as soon as it's done it start all over again...

#2 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 17 July 2006 - 04:32 PM

something like this will help
<body onload="show_time();">
<script language="javascript">
	function show_time(){
		var today = new Date();
		var time_dif = "";
		
		if (today.getHours() > 8) var odt = new Date(today.getFullYear(), today.getMonth(), today.getDate()+1, 9, 0, 0);
		else var odt = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 9, 0, 0);
		
		var d_time = odt.getTime() - today.getTime();
				
		var f_minutes = (d_time/1000)/60;
		var i_minutes = Math.floor(f_minutes);
		var seconds = parseInt((f_minutes - i_minutes) * 60);
		
		var f_hours = i_minutes / 60;
		var i_hours = Math.floor(f_hours);
		var minutes = parseInt((f_hours - i_hours) * 60);
		
		if (i_hours > 0) time_dif = i_hours + " hours, ";
		if (minutes > 0) time_dif += minutes + " minutes ";
		if (seconds > 0) time_dif += "and " + seconds + " seconds ";
		
		time_dif += "until " + odt;
		
		document.getElementById('time_div').innerHTML = time_dif;
		
	}
	setInterval("show_time()", 1000);
</script>
<div id="time_div">

</div>
</body>

NoGray.com


#3 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 17 July 2006 - 07:48 PM

thanks nogray but for some reason it keeps giving me the countdown for the day after, like right now it's almost 4pm and it tells me that there's 17 hours left before 9pm...

I can't seem to find what to change though... any clues?

#4 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 17 July 2006 - 08:39 PM

I set it up for 9am, you can change it to 9 bm by changing the 9 to 21 (military time) and the 8 to 20

NoGray.com


#5 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 17 July 2006 - 09:21 PM

ahhh didn't know t was military time, thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users