js时间戳转日期格式


时间戳转日期格式:yyyy-MM-dd HH:mm:ss
dealWithDatetime(datetime) {
      if (datetime) {
        const date = new Date(datetime);
        const year = date.getFullYear();
        let month = date.getMonth() + 1;
        month = month < 10 ? "0" + month : month;
        const day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        let h = date.getHours();
        h = h < 10 ? "0" + h : h;
        let m = date.getMinutes();
        m = m < 10 ? "0" + m : m;
        let s = date.getSeconds();
        s = s < 10 ? "0" + s : s;
        const time =
          year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;
        return time;
      } else {
        return "";
      }
    },

 

posted @ 2019-11-05 16:45  zigood  阅读(202)  评论(0)    收藏  举报