Home > Web Front-end > JS Tutorial > body text

How to display the current time in js (code)

不言
Release: 2018-08-20 14:56:07
Original
2138 people have browsed it

The content of this article is about how js implements the display of the current time (code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

<html>
  <head>
    <title>js实现当前日期显示</title>

   
  </head>

  <body style="text-align: center">

    <div>
      <span id="curTime" style="font-size: 18px;color: #00be67"></span>
    </div>

  </body>

  <script type="text/javascript" charset="utf-8">
  $(function(){

  var date = new Date();
          var weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
          var year = date.getFullYear();
          var month = date.getMonth()+1;
          var day = date.getDate();
          var week = weekDay[date.getDay()];         
          $("#curTime").html(year+"年"+month+"月"+day+"日&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"+week);
})

   
  </script>

</html>
Copy after login

Related recommendations:

js display time js display last modified time_javascript skills

JS jQuery displays boot time (Accurate to seconds)

#JS implements real-time display of time

The above is the detailed content of How to display the current time in js (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
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