<span style="text-align: right; padding: 0px;" id="nowTime">2016年4月26日 星期二 下午3:39:23</span>
<script type="text/javascript">
window.onload = function () {
// 今天是2013年12月20日 上午10:10
var chId = document.getElementById("nowTime");
function geTime() {
var nTime = new Date();
var nY = nTime.getFullYear();
var nM = nTime.getMonth() + 1;
var nD = nTime.getDate();
var nH = nTime.getHours();
var nMi = nTime.getMinutes();
var nS = nTime.getSeconds();
var nSe = ((nTime.getSeconds() % 2) == 1) ? ":" : " ";
function initArray() {
for (i = 0; i < initArray.arguments.length; i++)
this[i] = initArray.arguments[i];
}
var isnDays = new initArray("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日");
nMi = nMi > 9 ? nMi : "0" + nMi;
if (nH > 5 && nH < 12) {
//nH=nH>9?nH:"0"+nH;
nH = "上午" + nH;
}
else if (nH > 11 && nH < 18) {
nH = nH - 12;
//nH=nH>9?nH:"0"+nH;
nH = "下午" + nH;
}
else if (nH > 17 && nH < 24) {
nH = nH - 12;
//nH=nH>9?nH:"0"+nH;
nH = "晚上" + nH;
}
else {
//nH="0"+nH;
nH = "凌晨" + (nH);
}
nS = nS > 9 ? nS : "0" + nS;
str = nY + "年" + nM + "月" + nD + "日 " + isnDays[nTime.getDay()] + " " + nH + ":" + nMi + ":" + nS;
chId.innerHTML = str;
setTimeout(geTime, 1000);
}
geTime()
}
</script>