js公共时间戳方法es6

timestampToTime(timestamp, state) {
      var date = new Date(timestamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
      var YM = (date.getMonth() + 1).toString();
      var Y = date.getFullYear() + '-';
      var M = (date.getMonth() + 1).toString().padStart(2, 0) + '-';
      var D =
        date
          .getDate()
          .toString()
          .padStart(2, 0) + ' ';

      var h =
        date
          .getHours()
          .toString()
          .padStart(2, 0) + ':';
      var m =
        date
          .getMinutes()
          .toString()
          .padStart(2, 0) + ':';

      var s = date
        .getSeconds()
        .toString()
        .padStart(2, 0);
      return state ? Y + M + D + h + m + s : Y + M + D;
    },
var startTime = this.timestampToTime(this.cancelTime[0], true);
var endTime = this.timestampToTime(this.cancelTime[1], true);
posted @ 2019-06-18 15:44  影思密达ing  阅读(1166)  评论(0编辑  收藏  举报