Uptime java timer help ?

Discussion in 'JavaScript' started by travelmate, Sep 6, 2010.

  1. #1
    Hello !

    I have try to create my own livescore table for my league. So for the uptime minutes timer i use the below script. And my problem is this and i need you help. With this code below everything start to work fine and when the minutes go to 59-60' then it start the timer from the begin 1' first minute to count again. So i need a change the code for the timer to don't stop to account because i need the timer to go to 90' +

    Can someone change my code to work for more minutes than 60' ?

    Thanks

    <script type="text/javascript">
    
    /***********************************************
    * Dynamic CountUp script- © Dynamic Drive (http://www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit http://www.dynamicdrive.com/ for this script and 100s more.
    ***********************************************/
    
    function dcountup(startingdate, baseunit){
    	this.currentTime=new Date()
    	this.startingdate=new Date(startingdate)
    	this.timesup=false
    	this.baseunit=baseunit
    	this.start()
    }
    
    dcountup.prototype.oncountup=function(){} //default action for "oncountup"
    
    dcountup.prototype.start=function(){
    	var thisobj=this
    	this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
    	var timediff=(this.currentTime-this.startingdate)/1000 //difference btw target date and current date, in seconds
    	var oneMinute=60 //minute unit in seconds
    	var oneHour=60*60 //hour unit in seconds
    	var oneDay=60*60*24 //day unit in seconds
    	var dayfield=Math.floor(timediff/oneDay)
    	var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
    	var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
    	var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
    	if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
    		hourfield=dayfield*24+hourfield
    		dayfield="n/a"
    	}
    	else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
    		minutefield=dayfield*24*60+hourfield*60+minutefield
    		dayfield=hourfield="n/a"
    	}
    	else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
    		var secondfield=timediff
    		dayfield=hourfield=minutefield="n/a"
    	}
    	var result={days: dayfield, hours:hourfield, minutes:minutefield, seconds:secondfield}
    	this.oncountup(result)
    	setTimeout(function(){thisobj.start()}, 1000) //update results every second
    }
    
    </script>
    </head>
    
    <body bgcolor="#FFFFFF">
    <div id="cpcontainer">&nbsp;</div>
    
    <script type="text/javascript">
    
    //SYNTAX: myvariable=new dcountup(past_date_and_time_string, "baseunit")
    var princewedding=new dcountup("August 30, 2010 13:40:00", "days")
    
    princewedding.oncountup=function(result){
    	//result is an object containing the current count up date/time, updated every second
    	//Available properties: result["days"], result["hours"], result["minutes"], and result["seconds"]
    	var mycountainer=document.getElementById("cpcontainer")
    	mycountainer.innerHTML="<span class='dcountstyle'>"+result['minutes']+" <sup></sup> "
    }
    
    </script>
    </body>
    Code (markup):

     
    travelmate, Sep 6, 2010 IP