首页 > Web开发 > 详细

js 时间New Date()与setDate()参数

时间:2019-12-10 15:42:00      阅读:95      评论:0      收藏:0      [点我收藏+]

js 时间New Date()与setDate()参数

export function formatDateTime(dateTime, fmt) {
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (dateTime.getFullYear() + ‘‘).substr(4 - RegExp.$1.length));
  }
  let o = {
    M+: dateTime.getMonth() + 1,
    d+: dateTime.getDate(),
    H+: dateTime.getHours(),
    m+: dateTime.getMinutes(),
    s+: dateTime.getSeconds()
  };
  for (let k in o) {
    if (new RegExp(`(${k})`).test(fmt)) {
      let str = o[k] + ‘‘;
      fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : padLeftZero(str));
    }
  }
  return fmt;
}

function padLeftZero (str) {
  return (00 + str).substr(str.length);
}

 

js 时间New Date()与setDate()参数

原文:https://www.cnblogs.com/wn798/p/12016832.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!