原生js電子時計
1528 ワード
function $(id){
return document.getElementById(id);
}
var mon=["1","2","3","4","5","6","7","8","9","10","11","12"];
var week=[" "," "," "," "," "," "," "];
clock();
function clock(){
var d=new Date();
// , , ,
var y=d.getFullYear();
var m=d.getMonth();
var r=d.getDate();
var w=d.getDay();
// date
$("date").innerHTML=y+" "+mon[m]+" "+r+" ";
$('day').innerHTML=" "+week[w];
//
var h=d.getHours()<10?"0"+d.getHours():d.getHours();
var min=d.getMinutes()<10?"0"+d.getMinutes():d.getMinutes();
var s=d.getSeconds()<10?"0"+d.getSeconds():d.getSeconds();
$('time').innerHTML=h+":"+min+":"+s;
}
setInterval(clock,1000);