//Author unknown - modified by henrik function countdown_clock(year, month, day, hour, minute, second, format, divid) { //I chose a div as the container for the timer, but //it can be an input tag inside a form, or anything //who's displayed content can be changed through //client-side scripting. html_code = '
'; document.write(html_code); Today = new Date(); Todays_Year = Today.getYear() - 2000; Todays_Month = Today.getMonth() + 1; //Computes the time difference between the client computer and the server. Server_Date = (new Date(12, 2, 7, 0, 41, 22)).getTime(); Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); countdown(year, month-1, day, hour, minute, second, (Todays_Date - Server_Date), format, divid); } function countdown(year, month, day, hour, minute, second, time_difference, format, divid) { Today = new Date(); Todays_Year = Today.getYear() - 2000; Todays_Month = Today.getMonth(); //Convert today's date and the target date into miliseconds. Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); Target_Date = (new Date(year, month, day, hour, minute, second)).getTime(); //Find their difference, and convert that into seconds. //Taking into account the time differential between the client computer and the server. Time_Left = Math.round((Target_Date - Todays_Date + time_difference) / 1000); if(Time_Left < 0) Time_Left = 0; switch(format) { case 0: //The simplest way to display the time left. document.getElementById(divid).innerHTML = Time_Left + ' seconds'; break; case 1: //More datailed. days = Math.floor(Time_Left / (60 * 60 * 24)); Time_Left %= (60 * 60 * 24); hours = Math.floor(Time_Left / (60 * 60)); Time_Left %= (60 * 60); minutes = Math.floor(Time_Left / 60); Time_Left %= 60; seconds = Time_Left; dps = 's'; hps = 's'; mps = 's'; sps = 's'; //ps is short for plural suffix. if(days == 1) dps =''; if(hours == 1) hps =''; if(minutes == 1) mps =''; if(seconds == 1) sps =''; document.getElementById(divid).innerHTML = days + ' day' + dps + ' '; document.getElementById(divid).innerHTML += hours + ' hour' + hps + ' '; document.getElementById(divid).innerHTML += minutes + ' minute' + mps + ' and '; document.getElementById(divid).innerHTML += seconds + ' second' + sps; break; case 2: //Output: HH:MM:SS - mod by henrik hours = Math.floor(Time_Left / (60 * 60)); Time_Left %= (60 * 60); minutes = Math.floor(Time_Left / 60); Time_Left %= 60; seconds = Time_Left; days=0; //No single numbers if(hours < 10) hours ='0' + hours; if(minutes < 10) minutes ='0' + minutes; if(seconds < 10) seconds ='0' + seconds; //Not less than zero if(hours < 0) hours ='00'; if(minutes < 0) minutes ='00'; if(seconds < 0) seconds ='00'; document.getElementById(divid).innerHTML = ''; document.getElementById(divid).innerHTML += hours + ':'; document.getElementById(divid).innerHTML += minutes + ':'; document.getElementById(divid).innerHTML += seconds; if(hours==0 && minutes==0 && seconds==0) window.location = "?p=base&proj_upd=" + divid; //Time up - reload page break; default: document.getElementById(divid).innerHTML = Time_Left + ' seconds'; } //Recursive call, keeps the clock ticking. setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + second + ',' + time_difference + ', ' + format + ', ' + divid + ');', 1000); } // For dynamic server time /*********************************************** * Local Time 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. ***********************************************/ var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"] function showLocalTime(container, servermode, offsetMinutes, displayversion){ if (!document.getElementById || !document.getElementById(container)) return this.container=document.getElementById(container) this.displayversion=displayversion var servertimestring=(servermode=="server-php")? '' : (servermode=="server-ssi")? '' : '2/7/2012 7:41:22 AM' this.localtime=this.serverdate=new Date(servertimestring) this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time this.updateTime() this.updateContainer() } showLocalTime.prototype.updateTime=function(){ var thisobj=this this.localtime.setSeconds(this.localtime.getSeconds()+1) setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second } showLocalTime.prototype.updateContainer=function(){ var thisobj=this if (this.displayversion=="long") this.container.innerHTML=this.localtime.toLocaleString() else{ var hour=this.localtime.getHours() var minutes=this.localtime.getMinutes() var seconds=this.localtime.getSeconds() var month=(this.localtime.getMonth()+1) var date=this.localtime.getDate() //No single numbers if(hour < 10) hour ='0' + hour; if(minutes < 10) minutes ='0' + minutes; if(seconds < 10) seconds ='0' + seconds; if(month < 10) month ='0' + month; if(date < 10) date ='0' + date; var ampm=(hour>=12)? "PM" : "AM" var dayofweek=weekdaystxt[this.localtime.getDay()] //this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")" year=this.localtime.getYear(); if ((year>99) && (year<2000)){ year+=1900; } this.container.innerHTML=year+'-'+month+'-'+date+' '+hour+':'+minutes+':'+seconds; } setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second } function formatField(num, isHour){ if (typeof isHour!="undefined"){ //if this is the hour field var hour=(num>12)? num-12 : num return (hour==0)? 12 : hour } return (num<=9)? "0"+num : num//if this is minute or sec field } function CountUp(interval,max) { basResNew = parseInt(document.getElementById("cntdwn").innerHTML) + 1 if(basResNew>max){ basResNew = max; } document.getElementById("cntdwn").innerHTML = basResNew + " "; setTimeout("CountUp(" + (interval) + "," + max + ")", interval); } function CountDown(interval) { basMoneyNew = parseInt(document.getElementById("money").innerHTML) - 1 if(basMoneyNew<0){ basMoneyNew = 0; } document.getElementById("money").innerHTML = basMoneyNew + " "; setTimeout("CountDown(" + (interval) + ")", interval); } function putspan(spanname) { document.write(""); } function dateDifference(strDate1,strDate2){ datDate1= Date.parse(strDate1); datDate2= Date.parse(strDate2); dateDifference=(datDate2-datDate1)/1000; } function res_count(start,interval,max) { putspan('cntdwn'); document.getElementById("cntdwn").innerHTML = start-1; CountUp(interval,max); } function mon_count(start,interval) { putspan('money'); document.getElementById("money").innerHTML = start+1; CountDown(interval); } var entities=[ ['&','&'], [' ',' '] ]; function decodeHTML(e){ var clean = document.getElementById(e).innerHTML.replace(/<[^>]*>/g,""); for( var i=0, limit=entities.length; i < limit; ++i) { clean = clean.replace( new RegExp(entities[i][0],"ig"), entities[i][1]); } return clean; }