function countdown(obj) { this.obj = obj; this.Div = "clock"; this.BackColor = "white"; this.ForeColor = "black"; this.TargetDate = "12/31/2020 5:00 AM"; this.NowDate = "04/02/2012 17:45"; this.DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; this.CountActive = true; this.DisplayStr; this.Calcage = cd_Calcage; this.CountBack = cd_CountBack; this.Setup = cd_Setup; } function cd_Calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (s.length < 2) s = "0" + s; return (s); } function cd_CountBack(secs) { var hari=this.Calcage(secs,86400,100000) var jam=this.Calcage(secs,3600,24) var menit=this.Calcage(secs,60,60) var detik=this.Calcage(secs,1,60) //dibuat gini, supaya kalau waktunya dah lewat, gak keluar minusnya. kalau gak pakai ini, keluar minus kalau target timenya dah tercapai. if ((hari <= 0)&&(jam <= 0)&&(menit <= 0)&&(detik <= 0)) { hari='00'; jam='00'; menit='00'; detik='00'; var webinfonya= "» saat ini berlangsung"; } else { var webinfonya= "lagi"; } this.DisplayStr = this.DisplayFormat.replace(/%%D%%/g, hari); this.DisplayStr = this.DisplayStr.replace(/%%H%%/g, jam); this.DisplayStr = this.DisplayStr.replace(/%%M%%/g, menit); this.DisplayStr = this.DisplayStr.replace(/%%S%%/g, detik); this.DisplayStr = this.DisplayStr.replace(/%%WEBINFO%%/g, webinfonya); document.getElementById(this.Div).innerHTML = this.DisplayStr; if (this.CountActive) setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990); } function cd_Setup() { var dthen = new Date(this.TargetDate); var dnow = new Date(this.NowDate); ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); this.CountBack(gsecs); //document.write (dnow); }