本文实例讲述了javascript实现模拟时钟的方法。分享给大家供大家参考。具体实现方法如下:
javascript模拟时钟function Format2Len(i) {
// if (i < 10) {
// return "0" + i;
// }
// else {
// return i;
// }
return i < 10 ? "0" + i : i;
}
function RefreshClock() {
var CurrentTime = new Date();
var timeStr = CurrentTime.getFullYear() + "-" +
Format2Len(CurrentTime.getMonth()+1) + "-" +
Format2Len(CurrentTime.getDate()) + " " +
Format2Len(CurrentTime.getHours()) + ":" +
Format2Len(CurrentTime.getMinutes()) + ":" +
Format2Len(CurrentTime.getSeconds());
txtClock.value = timeStr;
}
setInterval("RefreshClock()", 1000);
当前时间:
希望本文所述对大家的javascript程序设计有所帮助。