Home>Article>Web Front-end> How to set time in html
htmlHow to set the time: first create a div; then add a class attribute to the div; finally set the time through the "function realSysTime(clock){...}" method.
The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.
HTML sets a current time
setInterval(function(){ realSysTime(clock),1000 }); //显示当前时间 function realSysTime(clock){ var now=new Date(); //创建Date对象 var year=now.getFullYear(); //获取年份 var month=now.getMonth(); //获取月份 var date=now.getDate(); //获取日期 var day=now.getDay(); //获取星期 var hour=now.getHours(); //获取小时 var minu=now.getMinutes(); //获取分钟 var sec=now.getSeconds(); //获取秒钟 month=month+1; var arr_week=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); var week=arr_week[day]; //获取中文的星期 var time=year+"年"+month+"月"+date+"日 "+" "+((hour<10)?('0'+hour):hour)+":"+((minu<10)?('0'+minu):minu)+":"+((sec<10)?('0'+sec):sec); //组合系统时间 clock.innerHTML=time; //显示系统时间 }
[Recommended learning:HTML video tutorial]
The above is the detailed content of How to set time in html. For more information, please follow other related articles on the PHP Chinese website!