Home > Web Front-end > Front-end Q&A > How to set time in html

How to set time in html

藏色散人
Release: 2023-01-04 09:36:02
Original
8290 people have browsed it

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)?(&#39;0&#39;+hour):hour)+":"+((minu<10)?(&#39;0&#39;+minu):minu)+":"+((sec<10)?(&#39;0&#39;+sec):sec);    //组合系统时间
    clock.innerHTML=time;    //显示系统时间
}
Copy after login
 <!-- 当前时间显示 -->
        <div id="clock" class="time" ></div>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template