function CountdownTimer(elm,tl,tl2,mes,mes2){ this.initialize.apply(this,arguments); } CountdownTimer.prototype = { initialize:function(elm,tl,tl2,mes,mes2){ this.elem = document.getElementById(elm); this.tl = tl; this.tl2 = tl2; this.mes = mes; this.mes2 = mes2; },countDown:function(){ var timer = ''; var today = new Date(); var period = this.tl - today; if(today > this.tl2){ if(period > 0){ var day = Math.floor(period / (24 * 60 * 60 * 1000)); var hour = Math.floor((period % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)); var min = Math.floor((period % (24 * 60 * 60 * 1000)) / (60 * 1000)) % 60; var sec = Math.floor((period % (24 * 60 * 60 * 1000)) / 1000) % 60 % 60; var milli = Math.floor((period % (24 * 60 * 60 * 1000)) / 10) % 100; var me = this; if(day) timer += ''+day+''; if(hour) timer += ''+hour+'時間'; timer += ''+this.addZero(min)+''+this.addZero(sec)+''+this.addZero(milli)+''; timer2 = 'あと';timer3 = 'です。';timer = timer2 + timer + timer3;this.elem.innerHTML = timer; tid = setTimeout( function(){me.countDown();},100); }else{ this.elem.innerHTML = this.mes; return; } } else{ var me = this; this.elem.innerHTML = this.mes2; tid = setTimeout( function(){me.countDown();},100); } },addZero:function(num){ return ('0'+num).slice(-2); } } function CDT(){ /* var tl = new Date('2015/12/9 00:00:00'); */ var tl = new Date('2018/1/10 00:00:00'); var tl2 = new Date('2024/5/8 07:36:02'); var timer = new CountdownTimer('CDT',tl,tl2,'販売は終了しました。',''); timer.countDown(); } window.onload=function(){ CDT(); }