var div = document.createElement("div");
function timeHandler(){
var date = new Date();
// console.log(date)
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDay();
var hour = date.getHours();
var minute = date.getMinutes();
var seconds = date.getSeconds();
div.innerText = year + "年" + month + "月" + day + "日 " + format(hour) + ":" + format(minute) + ":" + format(seconds);
document.body.appendChild(div)
}
timeHandler();
setInterval(timeHandler,1000);
function format(time) {
if (time < 10){
return "0" + time
}else {
return time
}
}
js时钟功能的实现
最新推荐文章于 2024-03-08 10:39:10 发布