时间格式化和数字分割(记录)

时间格式化

formatDate(date) {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, "0");
      const day = String(date.getDate()).padStart(2, "0");
      const hours = String(date.getHours()).padStart(2, "0");
      const minutes = String(date.getMinutes()).padStart(2, "0");
      const seconds = String(date.getSeconds()).padStart(2, "0");

      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
      // 格式 2023-08-29 10:24:00
    },

 数字分割

          const total = '0000000000'

          // 数字分割和逗号添加
          const formatted = total
            .toString()
            .replace(/\B(?=(\d{3})+(?!\d))/g, ',')
          // console.log(formatted) 0,000,000,000
          this.captionDataSum = formatted.split('')

猜你喜欢

转载自blog.csdn.net/weixin_53322542/article/details/134403491