javascript一秒重新整理一次顯示時間
阿新 • • 發佈:2018-12-30
function showtime(){
var now=new Date();
var year=now.getFullYear();
var month=now.getMonth()+1;
var day=now.getDate();
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
if(hours<10){hours="0"+hours;}
if(minutes<10){minutes="0"+minutes;}
if(seconds<10){seconds="0"+seconds;}
if(hours >=15){
hours = '15';
minutes ='00';
seconds ='00';
}
document.all.timeshow.innerHTML=""+year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+"";
//一秒重新整理一次顯示時間
var timeID=setTimeout(showtime,1000);
}
var now=new Date();
var year=now.getFullYear();
var month=now.getMonth()+1;
var day=now.getDate();
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
if(hours<10){hours="0"+hours;}
if(minutes<10){minutes="0"+minutes;}
if(seconds<10){seconds="0"+seconds;}
if(hours >=15){
hours = '15';
minutes ='00';
seconds ='00';
}
document.all.timeshow.innerHTML=""+year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+"";
//一秒重新整理一次顯示時間
var timeID=setTimeout(showtime,1000);
}