zoukankan      html  css  js  c++  java
  • 完整显示当前日期和时间的JS代码

     1 代码
     2 
     3 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> <script>
     4         function tick() {
     5             var hours, minutes, seconds, xfile;
     6             var intHours, intMinutes, intSeconds;
     7             var today, theday;
     8             today = new Date();
     9             function initArray() {
    10                 this.length = initArray.arguments.length
    11                 for (var i = 0; i < this.length; i++)
    12                     this[i + 1] = initArray.arguments[i]
    13             }
    14             var d = new initArray(
    15                 "星期日",
    16                 "星期一",
    17                 "星期二",
    18                 "星期三",
    19                 "星期四",
    20                 "星期五",
    21                 "星期六");
    22             theday = today.getFullYear() + "年" + [today.getMonth() + 1] + "月" + today.getDate() + d[today.getDay() + 1];
    23             intHours = today.getHours();
    24             intMinutes = today.getMinutes();
    25             intSeconds = today.getSeconds();
    26             if (intHours == 0) {
    27                 hours = "12:";
    28                 xfile = "午夜";
    29             } else if (intHours < 12) {
    30                 hours = intHours + ":";
    31                 xfile = "上午";
    32             } else if (intHours == 12) {
    33                 hours = "12:";
    34                 xfile = "正午";
    35             } else {
    36                 intHours = intHours - 12
    37                 hours = intHours + ":";
    38                 xfile = "下午";
    39             }
    40             if (intMinutes < 10) {
    41                 minutes = "0" + intMinutes + ":";
    42             } else {
    43                 minutes = intMinutes + ":";
    44             }
    45             if (intSeconds < 10) {
    46                 seconds = "0" + intSeconds + " ";
    47             } else {
    48                 seconds = intSeconds + " ";
    49             }
    50             timeString = theday + xfile + hours + minutes + seconds;
    51             Clock.innerHTML = timeString;
    52             window.setTimeout("tick();", 100);
    53         }
    54         window.onload = tick; 
    55     </script>
    <div id="Clock" align="center" style="font-size: 12px; color:#000000"></div> 
  • 相关阅读:
    easyui的datagrid右侧没有边框线
    移除input在type="number"时的上下箭头
    端口被占用的解决办法
    给DOM操作生成的元素添加事件
    前端工具——Gulp篇
    python类型学习
    python对象学习
    Python之系统交互(subprocess)
    如何准确高效的获取数据库新插入数据的主键id
    接口和抽象类有什么区别
  • 原文地址:https://www.cnblogs.com/jthb/p/3831216.html
Copyright © 2011-2022 走看看