www.webdeveloper.com
Results 1 to 7 of 7

Thread: [Request]Countdown timer.

  1. #1
    Join Date
    Jan 2010
    Posts
    4

    [Request]Countdown timer.

    Hello, im searching for a countdown timer script that wont restart when you refresh the page. I would like it to show day and how many hours its left. And when it hits 0 it sould restart automaticly again.

    Kind regards //Alex

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,389

    Lightbulb

    Quote Originally Posted by Zneeky View Post
    Hello, im searching for a countdown timer script that wont restart when you refresh the page. I would like it to show day and how many hours its left. And when it hits 0 it sould restart automaticly again.

    Kind regards //Alex
    How many hours left until when? noon? midnight? other?

    Instead of a countdown timer, why not just use the time of day and subtract from your desired time?

    Some examples of this already exist on this forum. Try a forum search with "countdown" or 'timer' or 'setTimeout' or similar keyword.

  3. #3
    Join Date
    Jan 2010
    Posts
    4
    Quote Originally Posted by JMRKER View Post
    How many hours left until when? noon? midnight? other?

    Instead of a countdown timer, why not just use the time of day and subtract from your desired time?

    Some examples of this already exist on this forum. Try a forum search with "countdown" or 'timer' or 'setTimeout' or similar keyword.
    I need one for example 13days 23h 59min 59sec, and one for 1h 59min 59sec. And when it hits 0 it should start all over again automatilcy.

    But ill try searching again if it has been posted something like this.
    And thank you for answer.

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,389

    Question

    Quote Originally Posted by Zneeky View Post
    I need one for example 13days 23h 59min 59sec, and one for 1h 59min 59sec. And when it hits 0 it should start all over again automatilcy.

    But ill try searching again if it has been posted something like this.
    And thank you for answer.
    JS has no way to save the interval once you exit the script, unless you save as a cookie.
    But then, the countdown only applies to that user's computer and none else.

    You can specify a certain day-time (or even hour-minute-second) to countdown to
    but that setting either needs to be hard-coded into your script
    or needs to be retrieved from a database or file via an AJAX application.

    Have you considered that limitation in your request to use a JS?
    Let's see the code you are trying to use (any attempt).

  5. #5
    Join Date
    Jan 2010
    Posts
    4
    Is it able to change this so it is in GMT+9?

    Code:
    <script type="text/javascript">
    
    
    dateFuture = new Date(2010,1,7,2,0,0);
    
    
    function GetCount(){
    
    	dateNow = new Date();									//grab current date
    	amount = dateFuture.getTime() - dateNow.getTime();		//calc milliseconds between dates
    	delete dateNow;
    
    	// time is already past
    	if(amount < 0){
    		document.getElementById('countbox').innerHTML="Now!";
    	}
    	// date is still good
    	else{
    		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 +" day"+((days!=1)?"s":"")+", ";}
    		if(days != 0 || hours != 0){out += hours +" hour"+((hours!=1)?"s":"")+", ";}
    		if(days != 0 || hours != 0 || mins != 0){out += mins +" minute"+((mins!=1)?"s":"")+", ";}
    		out += secs +" seconds";
    		document.getElementById('countbox').innerHTML=out;
    
    		setTimeout("GetCount()", 1000);
    	}
    }
    
    window.onload=GetCount;//call when everything has loaded
    
    </script>
    <div id="countbox"></div>
    Last edited by Zneeky; 01-26-2010 at 01:46 PM.

  6. #6
    Join Date
    Jan 2010
    Posts
    4
    I have tried with this dateNow = new getTime()+32400000); But then it got all messed up.

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,389

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles