zoukankan      html  css  js  c++  java
  • 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>
    

      

  • 相关阅读:
    picturebox 图片自适应
    C#中如何生成矢量图
    测试ODBC与OLE
    ODBC具体使用
    C#中的OLEDB连接2
    C#中的ODBC、OLEDB连接
    c#执行并行任务之Parallel与TaskFactory
    C# 4.0 新特性之并行运算(Parallel)
    app的下载中心
    第三方库列表
  • 原文地址:https://www.cnblogs.com/sallon/p/2602271.html
Copyright © 2011-2022 走看看