Home>Article>Web Front-end> How to set time in html

How to set time in html

藏色散人
藏色散人 Original
2021-04-12 09:52:43 8175browse

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.

How to set time in html

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; //显示系统时间 }
 

How to set time in html

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn