head-img Force's Blog

js获取本周7天所有日期并转换为H:i:s自动补0

JavaScript
datetimeFormat() {
      function paddingZero(number) {
        const length = String(number).length;
        return length === 1 ? '0'+number : number;
      }
      this.timer = setInterval(() => {
        let month = paddingZero((new Date()).getMonth() + 1);
        let day = paddingZero((new Date()).getDate());
        let hours = paddingZero((new Date()).getHours());
        let minutes = paddingZero((new Date()).getMinutes());
        let seconds = paddingZero((new Date()).getSeconds());
        this.datetime = `${(new Date()).getFullYear()}/${month}/${day} ${hours}:${minutes}:${seconds}`;
      }, 1000);
    },
点我评论
打赏本文
二维码


128

文章

14

标签

 访客统计  Update-******