new Data()获取到的值改为2019-11-16 12:35:00的格式

写的是移动端,用的vant中的时间组件。但是这个时间便利方法是公用的。能够将new Data()的值变为2019-11-16 12:35:00的格式

 /**
     * 选择时间确认事件
     * @author ex_maruihua
     * @updata ex_maruihua(2019/11/26--09点44分)
     * @param {Date} val 用户选择的时间结果
     */
    okdatetime(val) {
      const d = new Date(val);
      const resDate =
        d.getFullYear() +
        '-' +
        this.p(d.getMonth() + 1) +
        '-' +
        this.p(d.getDate());
      const resTime =
        this.p(d.getHours()) +
        ':' +
        this.p(d.getMinutes()) +
        ':' +
        this.p(d.getSeconds());
      this.isdatatime = false;
      this.lossDate = resDate + ' ' + resTime;
      return resDate + ' ' + resTime;
    },
    /**
     * 时间遍历方法
     * @author ex_maruihua
     * @updata ex_maruihua(2019/12/26--09点44分)
     * @param {Date} s 得到的时间结果
     */
    p(s) {
      return s < 10 ? '0' + s : s;
    },

猜你喜欢

转载自www.cnblogs.com/maruihua/p/12018052.html
new