系统时间对象-简易时钟
fwxstar 2018-07-17 702次浏览
摘要:
window.onload = function () {
var oBody=document.body;
f...
window.onload = function () { var oBody=document.body; fnTime(); setInterval(fnTime,1000); function fnTime() { // 系统时间 // object var myTime=new Date(); //当前系统的时间对象 //num var iYear=myTime.getFullYear(); //年 var iMonth=myTime.getMonth()+ 1 ; //月 (从0开始) var iDate=myTime.getDate(); //日 var iWeek=myTime.getDay(); // 星期 var iHours=myTime.getHours(); // 时 var iMinutes=myTime.getMinutes(); // 分 var iSeconds=myTime.getSeconds(); // 秒 if(iWeek === 0) iWeek = "星期日"; if(iWeek === 1) iWeek = "星期一"; if(iWeek === 2) iWeek = "星期二"; if(iWeek === 3) iWeek = "星期三"; if(iWeek === 4) iWeek = "星期四"; if(iWeek === 5) iWeek = "星期五"; if(iWeek === 6) iWeek = "星期六"; str = iYear + "年"+ iMonth + "月" + iDate + "日" + iWeek + towNum(iHours) +":"+ towNum(iMinutes) +":"+ towNum(iSeconds); oBody.innerHTML = str; } }; function towNum(n) { return n < 10 ? "0" + n : n; }
- 上一篇:倒计时原理
- 下一篇:一个简单的js动画函数封装