当前位置 : 主页 > 网络编程 > JavaScript >

yyyy_MM_dd输出2017_06_24.txt

来源:互联网 收集:自由互联 发布时间:2021-06-30
yyyy_MM_dd输出2017_06_24.txt Date.prototype.Format = function(fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, "d+": this.getDate(), "h+": this.getHours(), "m+": this.getMinutes(), "s+": this.getSeconds(), "q+": Math.floor((thi
yyyy_MM_dd输出2017_06_24.txt
Date.prototype.Format = function(fmt) { //author: meizz 
      var o = {
          "M+": this.getMonth() + 1,
          "d+": this.getDate(),
          "h+": this.getHours(),
          "m+": this.getMinutes(),
          "s+": this.getSeconds(),
          "q+": Math.floor((this.getMonth() + 3) / 3),
          "S": this.getMilliseconds()
      };

      console.log("o=" + JSON.stringify(o));

      if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));


      for (var k in o)
          if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
      return fmt;
  }

  var ilog = new Date().Format("yyyy_MM_dd");
  console.log("ilog=" + ilog); //输出  ilog=2017_06_24
网友评论