• javaScript输出指定的时间格式 程序员


     1 <script language="JavaScript" type="text/javascript">
     2 function nowTime(format)
     3 {
     4 var dt=new Date();
     5 //年份
     6 this.Year=dt.getFullYear();
     7 //月份
     8 this.Month=dt.getMonth()+1;
     9 //日期
    10 this.Day=dt.getDate();
    11 //星期几,数字
    12 this.Week=dt.getDay();
    13 //星期几,中文
    14 this.WeekDay='日一二三四五六'.charAt(dt.getDay()); 
    15 //24制小时
    16 this.Hours24=dt.getHours();
    17 //12制小时
    18 this.Hours12=this.Hours24>12 ? this.Hours24-12 : this.Hours24; 
    19 //分钟
    20 this.Minutes=dt.getMinutes();
    21 //
    22 this.Seconds=dt.getSeconds();
    23 format=format.replace("yy",this.Year);
    24 format=format.replace("MM",this.Month);
    25 format=format.replace("dd",this.Day);
    26 format=format.replace("HH",this.Hours24);
    27 format=format.replace("hh",this.Hours12);
    28 format=format.replace("mm",this.Minutes);
    29 format=format.replace("ss",this.Seconds);
    30 format=format.replace("ww",this.Week);
    31 format=format.replace("WW",this.WeekDay); 
    32 //时间显示在页面中哪个标签里,这里是其id
    33 this.toShow=function (element)
    34 {
    35       document.getElementById(element).innerHTML=format;
    36 } 
    37 }
    38 </script>

    上面是写在<header></header>标签中的

    下面是制定先是在网页的某个位置的!

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

      

  • 相关阅读:
    this和$(this)的关系
    单色边表格
    php概率算法
    jQuery Ajax 参数解析
    拍拍CPS入门使用
    飞鸽端口被占
    浏览器调试工具技巧分享
    事件click,bind,click
    jQuery旋转插件—rotate
    利用谷歌API生成二维码
  • 原文地址:https://www.cnblogs.com/sallon/p/2602271.html
Copyright © 2020-2023  润新知