• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. JavaScript日期時間格式化函數

        時間:2024-08-29 22:03:25 JavaScript 我要投稿
        • 相關推薦

        JavaScript日期時間格式化函數

          函數代碼:

        JavaScript日期時間格式化函數

          復制代碼 代碼如下:

          Date.prototype.format = function(format){

          var o = {

          "M+" : this.getMonth()+1, //month

          "d+" : this.getDate(), //day

          "h+" : this.getHours(), //hour

          "m+" : this.getMinutes(), //minute

          "s+" : this.getSeconds(), //second

          "q+" : Math.floor((this.getMonth()+3)/3), //quarter

          "S" : this.getMilliseconds() //millisecond

          }

          if(/(y+)/.test(format)) format=format.replace(RegExp.$1,

          (this.getFullYear()+"").substr(4 - RegExp.$1.length));

          for(var k in o)if(new RegExp("("+ k +")").test(format))

          format = format.replace(RegExp.$1,

          RegExp.$1.length==1 ? o[k] :

          ("00"+ o[k]).substr((""+ o[k]).length));

          return format;

          }

          調用示例:

          復制代碼 代碼如下:

          setInterval(function(){

          var time = new Date().format("hh:mm:ss");

          var date = new Date().format("yyyy-MM-dd");

          document.getElementById("Time").innerHTML=time;

          document.getElementById("Date").innerHTML=date;

          },1000);

        《&.doc》
        将本文的Word文档下载到电脑,方便收藏和打印
        推荐度:
        点击下载文档

        【JavaScript日期時間格式化函數】相關文章:

        淺析jQuery 遍歷函數javascript03-29

        Javascript函數的定義和用法分析03-31

        JavaScript中push(),join() 函數實例詳解03-31

        最常用的20個javascript方法函數03-10

        英語日期時間的表達03-06

        JavaScript中常見的字符串操作函數及用法07-24

        Excel日期與時間設置教程03-03

        JavaScript基于正則表達式數字判斷函數03-31

        有關javascript實現的多個層切換效果通用函數示例03-31

        在线咨询
        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 另类专区亚洲色 | 亚洲欧美动漫卡通一区二区 | 亚洲综合精品久久玖玖玖 | 午夜福利精品在线 | 日本一区二区三区不卡片高清 | 亚洲国产精品ⅴa在线播放 中文字幕羞羞视频网站 |

            JavaScript日期時間格式化函數

              函數代碼:

            JavaScript日期時間格式化函數

              復制代碼 代碼如下:

              Date.prototype.format = function(format){

              var o = {

              "M+" : this.getMonth()+1, //month

              "d+" : this.getDate(), //day

              "h+" : this.getHours(), //hour

              "m+" : this.getMinutes(), //minute

              "s+" : this.getSeconds(), //second

              "q+" : Math.floor((this.getMonth()+3)/3), //quarter

              "S" : this.getMilliseconds() //millisecond

              }

              if(/(y+)/.test(format)) format=format.replace(RegExp.$1,

              (this.getFullYear()+"").substr(4 - RegExp.$1.length));

              for(var k in o)if(new RegExp("("+ k +")").test(format))

              format = format.replace(RegExp.$1,

              RegExp.$1.length==1 ? o[k] :

              ("00"+ o[k]).substr((""+ o[k]).length));

              return format;

              }

              調用示例:

              復制代碼 代碼如下:

              setInterval(function(){

              var time = new Date().format("hh:mm:ss");

              var date = new Date().format("yyyy-MM-dd");

              document.getElementById("Time").innerHTML=time;

              document.getElementById("Date").innerHTML=date;

              },1000);