使用element的时间选择器--时间格式转换

时间格式转换

submit() {
      console.log(this.formatDate(this.form.date1[0]));   //this.form.date1[0])  为传入的时间
    },

    formatDate(date) {
      if (typeof date == "string") {
        return this.formatDate2(date);
      }
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      return y + "/" + m + "/" + d;
    },

    formatDate2(date) {
      var y = date.substring(0, 4);
      var m = date.substring(5, 7);
      var d = date.substring(8, 10);

      return y + "/" + m + "/" + d;
    }

你可能感兴趣的:(前端,element)