侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

js 继承date添加格式化

2024-05-07 星期二 / 0 评论 / 0 点赞 / 53 阅读 / 836 字

Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, // mo

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;  }

 

广告 广告

评论区