vue 日期格式化 获取两个日期相差天数

将时间转化为yyyy-mm-dd hh:mm:ss 格式

    //格式化时间
    formatTime (date, type = 1) {
      if (!(date instanceof Date)) {
        date = new Date(date)
      };
      const curDate = new Date();
      const curYear = curDate.getFullYear();
      const curMonth = curDate.getMonth() + 1;
      const curDay = curDate.getDate();
      const year = date.getFullYear();
      const month = date.getMonth() + 1;
      const day = date.getDate();
      const hour = date.getHours();
      const minute = date.getMinutes();
      const second = date.getSeconds();
      if (type === 1) {
        return [year, month, day].map(this.formatNumber).join('-') + ' ' + [hour, minute, second].map(this
          .formatNumber).join(':')
      } else if (type === 2) {
        return [year, month, day].map(this.formatNumber).join('-')
      } else if (type ==&

你可能感兴趣的:(vue,vue)