zoukankan      html  css  js  c++  java
  • JS获取系统时间--JavaScript基础

    1、网页中实时显示当前时间

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>页面上显示系统时间</title>
    </head>
    <body onload="showTime()">
      当前时间为:<span id="show"></span>
    </body>
    <script>
      function showTime() {
        var nowTime = new Date();
        var years = nowTime.getFullYear();
        var mouths = nowTime.getMonth();
        var days = nowTime.getDate();
        var hours = nowTime.getHours();
        var minites = nowTime.getMinutes();
        var seconds = nowTime.getSeconds();
        var time = years+"年";
        time += (mouths+1)+"月"+days+"日";
        time += (hours<10?"0":"")+hours;
        time += (minites<10?":0":":") + minites;
        time += (seconds<10?":0":":") + seconds;
        time += (hours>12)?"PM":"AM";
        document.getElementById("show").innerHTML = time;
        setTimeout("showTime()",1000);
        }
    </script>
    </html>

    2、实现效果:




  • 相关阅读:
    Fiddler基础与HTTP状态码
    Fiddler与F12设置代理
    人和机器猜拳游戏
    ng-model 取不到值
    git的使用
    笔记
    INSPIRED启示录 读书笔记
    INSPIRED启示录 读书笔记
    INSPIRED启示录 读书笔记
    INSPIRED启示录 读书笔记
  • 原文地址:https://www.cnblogs.com/qikeyishu/p/7577230.html
Copyright © 2011-2022 走看看