日期格式转换

/**
     * 时间戳转日期字符串
     * @param timestamp
     * @returns {*}
     */
    formatDateStr(row, column, cellValue) {
      return this.format2DateStr(cellValue);
    },
    format2DateStr: function (timestamp) {
      if (timestamp && timestamp !== '') {
        let date = new Date(timestamp);
        return formatDate(date, "yyyy-MM-dd hh:mm:ss");
      } else {
        return null;
      }
    },
    formatDate(date, fmt) {
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.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;
    }

日期格式转换 yyyy-MM-dd

    /* 日期格式转换 yyyy-MM-dd*/
    formatDate1(date) {
      var myyear = date.getFullYear();
      var mymonth = date.getMonth() + 1;
      var myweekday = date.getDate();
      if (mymonth < 10) {
        mymonth = "0" + mymonth;
      }
      if (myweekday < 10) {
        myweekday = "0" + myweekday;
      }
      return (myyear + "-" + mymonth + "-" + myweekday);
    },

你可能感兴趣的:(日期格式转换)