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
    Sep 2004
    Location
    Gympie, Queensland - Australia
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Countdown Script - Need Help

    Hello,

    I would like to know how to Modify.. This script to not show days

    Like, instend of 2 days, 10 hrs. ect...

    to show up as

    58 hrs, 30 mins 30 sec.. ect

    Can anyone help me

    Code:
    <span id="tzcd"></span>
    
    
    <!--Copy and paste just above the close </BODY> of you HTML webpage.-->
    
    <SCRIPT type="text/javascript">
    
    // ****  Time Zone Count Down Javascript  **** //
    /*
    Visit http://rainbow.arch.scriptmania.com/scripts/
     for this script and many more
    */
    
    ////////// CONFIGURE THE COUNTDOWN SCRIPT HERE //////////////////
    
    var month = '*';     //  '*' for next month, '0' for this month or 1 through 12 for the month 
    var day = '1';       //  Offset for day of month day or + day  
    var hour = 0;        //  0 through 23 for the hours of the day
    var tz = -5;         //  Offset for your timezone in hours from UTC
    var lab = 'tzcd';    //  The id of the page entry where the timezone countdown is to show
    
    function start() {displayTZCountDown(setTZCountDown(month,day,hour,tz),lab);}
    
        // **    The start function can be changed if required   **
    window.onload = start;
    
    ////////// DO NOT EDIT PAST THIS LINE //////////////////
    
    function setTZCountDown(month,day,hour,tz) 
    {
    var toDate = new Date();
    if (month == '*')toDate.setMonth(toDate.getMonth() + 1);
    else if (month > 0) 
    { 
    if (month <= toDate.getMonth())toDate.setYear(toDate.getYear() + 1);
    toDate.setMonth(month-1);
    }
    if (day.substr(0,1) == '+') 
    {var day1 = parseInt(day.substr(1));
    toDate.setDate(toDate.getDate()+day1);
    } 
    else{toDate.setDate(day);
    }
    toDate.setHours(hour);
    toDate.setMinutes(0-(tz*60));
    toDate.setSeconds(0);
    var fromDate = new Date();
    fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
    var diffDate = new Date(0);
    diffDate.setMilliseconds(toDate - fromDate);
    return Math.floor(diffDate.valueOf()/1000);
    }
    function displayTZCountDown(countdown,tzcd) 
    {
    if (countdown < 0) document.getElementById(tzcd).innerHTML = "Sorry, you are too late."; 
    else {var secs = countdown % 60; 
    if (secs < 10) secs = '0'+secs;
    var countdown1 = (countdown - secs) / 60;
    var mins = countdown1 % 60; 
    if (mins < 10) mins = '0'+mins;
    countdown1 = (countdown1 - mins) / 60;
    var hours = countdown1 % 24;
    var days = (countdown1 - hours) / 24;
    document.getElementById(tzcd).innerHTML = days + " day" + (days == 1 ? '' : 's') + ' ' +hours+ 'h : ' +mins+ 'm : '+secs+'s';
    setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999);
    }
    }
    </SCRIPT>
    Greg S
    ----------------------------------

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try changing the three lines near the bottom to this.

    Code:
    var hours = countdown1; // % 24;
    // var days = (countdown1 - hours) / 24;
    document.getElementById(tzcd).innerHTML = /* days + " day" + (days == 1 ? '' : 's') + ' ' + */ hours+ 'h : ' +mins+ 'm : '+secs+'s';
    Ironically I can't test it because it doesn't seem to work when I point it to tomorrow. Either it has trouble going across monthly boundaries or yearly ones or I'm using it incorrectly. I think it should work though.

    david_kw

  • #3
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm for some reason Edit isn't working. Anyway, I wanted to let you know it seems to work in IE7 across the year boundary. It was FF1.5 where it didn't work for me.

    david_kw

  • #4
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The problem appears to be

    toDate.getYear()

    which returns different things depending on the browser. See this link for more info.

    http://www.quirksmode.org/js/datecompat.html

    So if this is a problem you can probably change it to

    toDate.getFullYear()

    instead. That would change this line in your code.

    Code:
    if (month <= toDate.getMonth())toDate.setYear(toDate.getFullYear() + 1);
    Which makes it work in FF1.5 as well.

    david_kw

  • #5
    New to the CF scene
    Join Date
    Sep 2004
    Location
    Gympie, Queensland - Australia
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So what is the code Now...

    can you edit it.. as i'm hopeless in Javascipts
    Greg S
    ----------------------------------

  • #6
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Heh, ok I guess. I hope you can at least look at the differences between the scripts so you can learn something. I think of this forum as a place to ask questions so you can learn instead of somewhere to go to ask people to do work for you.

    Code:
    <span id="tzcd"></span>
    
    
    <!--Copy and paste just above the close </BODY> of you HTML webpage.-->
    
    <SCRIPT type="text/javascript">
    
    // ****  Time Zone Count Down Javascript  **** //
    /*
    Visit http://rainbow.arch.scriptmania.com/scripts/
     for this script and many more
    */
    
    ////////// CONFIGURE THE COUNTDOWN SCRIPT HERE //////////////////
    
    var month = '*';     //  '*' for next month, '0' for this month or 1 through 12 for the month 
    var day = '11';       //  Offset for day of month day or + day  
    var hour = 12;        //  0 through 23 for the hours of the day
    var tz = -5;         //  Offset for your timezone in hours from UTC
    var lab = 'tzcd';    //  The id of the page entry where the timezone countdown is to show
    
    function start() {displayTZCountDown(setTZCountDown(month,day,hour,tz),lab);}
    
        // **    The start function can be changed if required   **
    window.onload = start;
    
    ////////// DO NOT EDIT PAST THIS LINE //////////////////
    
    function setTZCountDown(month,day,hour,tz) 
    {
    var toDate = new Date();
    if (month == '*')toDate.setMonth(toDate.getMonth() + 1);
    else if (month > 0) 
    { 
    if (month <= toDate.getMonth())toDate.setYear(toDate.getFullYear() + 1);
    toDate.setMonth(month-1);
    }
    if (day.substr(0,1) == '+') 
    {var day1 = parseInt(day.substr(1));
    toDate.setDate(toDate.getDate()+day1);
    } 
    else{toDate.setDate(day);
    }
    toDate.setHours(hour);
    toDate.setMinutes(0-(tz*60));
    toDate.setSeconds(0);
    var fromDate = new Date();
    fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
    var diffDate = new Date(0);
    diffDate.setMilliseconds(toDate - fromDate);
    return Math.floor(diffDate.valueOf()/1000);
    }
    function displayTZCountDown(countdown,tzcd) 
    {
    if (countdown < 0) document.getElementById(tzcd).innerHTML = "Sorry, you are too late."; 
    else {var secs = countdown % 60; 
    if (secs < 10) secs = '0'+secs;
    var countdown1 = (countdown - secs) / 60;
    var mins = countdown1 % 60; 
    if (mins < 10) mins = '0'+mins;
    countdown1 = (countdown1 - mins) / 60;
    var hours = countdown1; // % 24;
    // var days = (countdown1 - hours) / 24;
    document.getElementById(tzcd).innerHTML = /* days + " day" + (days == 1 ? '' : 's') + ' ' + */ hours+ 'h : ' +mins+ 'm : '+secs+'s';
    setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999);
    }
    }
    </SCRIPT>
    david_kw

  • #7
    New to the CF scene
    Join Date
    Sep 2004
    Location
    Gympie, Queensland - Australia
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, for the help..

    As for me being able to code myself.. i would really like to learn, but the person teaching me would have to have Lots of space time..
    Greg S
    ----------------------------------


  •  

    Posting Permissions

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