下面是我正在处理的代码。通过阅读我在此网站上找到的答案之一,我将其从 24 小时格式时间更改为 12 小时格式时间。唯一的问题是 5 分钟前,时间是 2:5,我希望它显示 02:05。我不确定到底要改变什么。任何帮助将不胜感激。谢谢!
function theClock12hour()
{
function pad(n) {
return (n < 10) ? "0" + n : n;
}
var time = new Date();
var nHours = time.getHours();
var nMins = time.getMinutes();
if (nHours > 12) {
nHours -=12;
} else if (nHourse ===0) {
hours = 12;
}
document.getElementById("hourbox").innerHTML = nHours;
document.getElementById("minutebox").innerHTML = nMins;
var nDay = time.getDate();
document.getElementById("datebox").innerHTML = nDay;
var nMonth = time.getMonth();
if (nMonth == 0){ nMonth = 'JANUARY'; }
else if (nMonth == 1){ nMonth = 'FEBRUARY'; }
else if (nMonth == 2){ nMonth = 'MARCH'; }
else if (nMonth == 3){ nMonth = 'APRIL'; }
else if (nMonth == 4){ nMonth = 'MAY'; }
else if (nMonth == 5){ nMonth = 'JUNE'; }
else if (nMonth == 6){ nMonth = 'JULY'; }
else if (nMonth == 7){ nMonth = 'AUGUST'; }
else if (nMonth == 8){ nMonth = 'SEPTEMBER'; }
else if (nMonth == 9){ nMonth = 'OCTOBER'; }
else if (nMonth == 10){ nMonth = 'NOVEMBER'; }
else if (nMonth == 11){ nMonth = 'DECEMBER'; }
document.getElementById("monthbox").innerHTML = nMonth;
var nTday = time.getDay();
if (nTday == 0){ nTday='SUN'; }
else if (nTday == 1){ nTday='MON'; }
else if (nTday == 2){ nTday='TUE'; }
else if (nTday == 3){ nTday='WED'; }
else if (nTday == 4){ nTday='THU'; }
else if (nTday == 5){ nTday='FRI'; }
else if (nTday == 6){ nTday='SAT'; }
document.getElementById("daybox").innerHTML = nTday;
var nYear = time.getFullYear();
document.getElementById("yearbox").innerHTML = nYear;
timer = setTimeout("theClock12hour()",1000);
}