zoukankan      html  css  js  c++  java
  • javascript时钟

     <script language="JavaScript" type="text/javascript">
             function nowTime(format) {
                 var dt = new Date();
                 //年份
                 this.Year = dt.getFullYear();
                 //月份
                 this.Month = dt.getMonth() + 1;
                 //日期
                 this.Day = dt.getDate();
                 //星期几,数字
                 this.Week = dt.getDay();
                 //星期几,中文
                 this.WeekDay = '日一二三四五六'.charAt(dt.getDay());
                 //24制小时
                 this.Hours24 = dt.getHours();
                 //12制小时
                 this.Hours12 = this.Hours24 > 12 ? this.Hours24 - 12 : this.Hours24;
                 //分钟
                 this.Minutes = dt.getMinutes();
                 //秒
                 this.Seconds = dt.getSeconds();
                 format = format.replace("yy", this.Year);
                 format = format.replace("MM", this.Month);
                 format = format.replace("dd", this.Day);
                 format = format.replace("HH", this.Hours24);
                 format = format.replace("hh", this.Hours12);
                 format = format.replace("mm", this.Minutes);
                 format = format.replace("ss", this.Seconds);
                 format = format.replace("ww", this.Week);
                 format = format.replace("WW", this.WeekDay);
                 //时间显示在页面中哪个标签里,这里是其id
                 this.toShow = function (element) {
                     document.getElementById(element).innerHTML = format;
                 }
             }
    </script>

    调用

    <div id="time" >
    <script language="JavaScript" type="text/javascript" defer="defer">
        setInterval("new nowTime('yy年MM月dd日 HH:mm:ss 星期WW').toShow('time')", 1000);
    </script></div>

  • 相关阅读:
    StringBuffer和StringBuilder
    String类
    软件设计师考点总结(一)
    基于 Axis2的webService接口的基本开发步骤
    Linux学习Day10:LVM(逻辑卷管理器)
    Linux学习Day9:使用RAID(独立冗余磁盘阵列)
    Linux学习Day8:挂载硬盘设备、添加交换分区
    Linux学习Day7:用户身份与文件权限、su命令与sudo服务
    Linux学习Day6:编写Shell脚本、配置计划任务
    Linux学习Day5:Vim编辑器、配置网卡、配置Yum软件本地仓库
  • 原文地址:https://www.cnblogs.com/net-study/p/3287122.html
Copyright © 2011-2022 走看看