分享一个JS实现的即时显示时间的代码,包括秒自动获得
[JavaScript] 纯文本查看 复制代码
function CheckTimer() {
var str = document.getElementById("DateTimer");
var timer = new Date();
var year = timer.getFullYear();
var mouth = timer.getMonth()+1;
var date = timer.getDate();
var hour = timer.getHours();
var mitu = timer.getMinutes();
var se = timer.getSeconds();
str.innerHTML = year + "-" + mouth + "-" + date + " " + hour + ":" + mitu + ":" + se;
}
setInterval(CheckTimer, 1000);//每隔一秒调用CheckTimer函数
|