时钟

//初始化时钟
function InitClock() {
window.setInterval(function () {
NavigationTime.value = timeToString(new Date(), "HH:mm:ss")
}, 1000);
}
//获取时间
function timeToString(oDate:any, format:any) {
let oYear = oDate.getFullYear(),
oMonth = oDate.getMonth() + 1,
oDay = oDate.getDate(),
oHour = oDate.getHours(),
oMin = oDate.getMinutes(),
oSen = oDate.getSeconds(),
oTime = oYear + '-' + getzf(oMonth) + '-' + getzf(oDay) + ' ' + getzf(oHour) + ':' + getzf(oMin) + ':' + getzf(oSen);//最后拼接时间
if (format != undefined) {
oTime = format.replace("yyyy", oYear).replace("MM", getzf(oMonth)).replace("dd", getzf(oDay)).replace("HH", getzf(oHour)).replace("mm", getzf(oMin)).replace("ss", getzf(oSen));
}

return oTime;
}

//补0操作
function getzf(num:any) {

if (parseInt(num) < 10) {
num = '0' + num;
}
return num;
}
posted @ 2022-05-19 10:03  小林222  阅读(66)  评论(0)    收藏  举报