Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Location
    London
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Javascript Countdown

    hi,
    i need to create a javascript countdown based on the times given. If the start time is 17:45 and the end time is 19:32 (in that format) for example, how would i create a countdown for the time between 17:45 and 19:32. If anyone could point me in the right direction that would be great!
    thanks

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,640
    Thanks
    6
    Thanked 1,004 Times in 977 Posts
    Just wanted to point out that it’s not nice to post the same question on multiple forums. You’re just wasting the time of people trying to help in one thread when the question might have been solved in the other one.

    Be patient and you will be helped eventually.

    Also, could you please elaborate for what kind of project you need this countdown?

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Location
    London
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    this is for my website. I have created a reminder system (using JavaScript) where people will be reminded at the time entered e.g. if you enter 18:45 - you will be reminded at that time to do something. What i would like to do now is to add a countdown, so people know how long is left until the time.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,920
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by Laurence485 View Post
    this is for my website. I have created a reminder system (using JavaScript) where people will be reminded at the time entered e.g. if you enter 18:45 - you will be reminded at that time to do something. What i would like to do now is to add a countdown, so people know how long is left until the time.


    Show your existing code and doubtless someone will modify it for you.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    Dec 2011
    Location
    London
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Code:
    var sethour = t.substr(0,2);
    var setminute = t.substr(3,2);
    var Hours = clockTime.substr(0,2);
    var Minutes = clockTime.substr(3,2);
    var Seconds = clockTime.substr(6,2);
    time_countdown(Hours,Minutes,Seconds,t,sethour,setminute); //show countdown time until reminder
    
    //print time left to div
    function time_countdown(h,m,s,st,sh,sm){
    
    var hoursleft = sh-h;
    if(hoursleft<0)hoursleft+=24;
    var minutesleft = sm-m-1;
    if(minutesleft<0){
    hoursleft-=1;
    minutesleft=60+minutesleft;
    }
    var secondsleft = 0-s;
    if(secondsleft<0)secondsleft=60+secondsleft;
    
    if(hoursleft<10)hoursleft="0"+hoursleft;
    if(minutesleft<10)minutesleft="0"+minutesleft;
    if(secondsleft<10)secondsleft="0"+secondsleft;
    
    $("#countdown").html(hoursleft+":"+minutesleft+":"+secondsleft);
    }
    This code prints the time left into the div with id "countdown"
    e.g. the time printed could be "11:18:58"

    I then need to have the time e.g. "11:18:58" turned into a countdown to 00:00:00 using setTimeout(), but i don't know how to do this

    thanks

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,920
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    You have not shown the whole of your code - there is no function clockTime(). shown.

    But the solution is simple. Wrap the whole thing in a function named (say) show(), and call the function repeatedly with

    setInterval(show,1000);

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    Laurence485 (12-19-2011)

  • #7
    New to the CF scene
    Join Date
    Dec 2011
    Location
    London
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks, i've sorted it now


  •  

    Posting Permissions

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