js 格式化当前时间

ゞ 浴缸里的玫瑰 2023-02-14 01:19 190阅读 0赞

2020-5-30

格式化当前时间

  1. Date.prototype.Format = function (fmt) {
  2. var o = {
  3. "M+": this.getMonth() + 1, //月份
  4. "d+": this.getDate(), //日
  5. "H+": this.getHours(), //小时
  6. "m+": this.getMinutes(), //分
  7. "s+": this.getSeconds(), //秒
  8. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  9. S: this.getMilliseconds(), //毫秒
  10. };
  11. if (/(y+)/.test(fmt))
  12. fmt = fmt.replace(
  13. RegExp.$1,
  14. (this.getFullYear() + "").substr(4 - RegExp.$1.length)
  15. );
  16. for (var k in o)
  17. if (new RegExp("(" + k + ")").test(fmt))
  18. fmt = fmt.replace(
  19. RegExp.$1,
  20. RegExp.$1.length === 1
  21. ? o[k]
  22. : ("00" + o[k]).substr(("" + o[k]).length)
  23. );
  24. return fmt;
  25. };
  26. new Date().Format("yyyy-MM-dd HH:mm:ss")

发表评论

表情:
评论列表 (有 0 条评论,190人围观)

还没有评论,来说两句吧...

相关阅读