小程序vant-weapp完整时间组件

完整时间选择器 

  type="datetime"

  value="{{ currentDate }}"

  min-date="{{ minDate }}"

  max-date="{{ maxDate }}"

  bind:input="onInput"

  bind:confirm="confirm"

  bind:cancel="cancel"

/>

 

//完整js

data: {

    motto: 'Hello World',

    userInfo: {},

    hasUserInfo: false,

    canIUse: wx.canIUse('button.open-type.getUserInfo'),

    minDate: new Date(new Date(new Date(new Date().toLocaleDateString()).getTime()).valueOf()-43200000),

    maxDate: new Date().getTime(),

    currentDate: new Date().getTime(),

    nowTime:'',

    // currentDate: new Date().getTime(),

  },

// 时间戳转换

  changeTime(time) {

    if (time) {

      var oDate = new Date(time * 1),

        oYear = oDate.getFullYear(),

        oMonth = oDate.getMonth() + 1,

        oDay = oDate.getDate(),

        oHour = oDate.getHours(),

        oMin = oDate.getMinutes(),

        oSen = oDate.getSeconds(),

        oTime =

          oYear +

          "-" +

          this.getBz(oMonth) +

          "-" +

          this.getBz(oDay) +

          " " +

          this.getBz(oHour) +

          ":" +

          this.getBz(oMin) +

          ":" +

          this.getBz(oSen); //拼接时间

      return oTime;

    } else {

      return "";

    }

  },

  // 补0

  getBz(num) {

    if (parseInt(num) < 10) {

      num = "0" + num;

    }

    return num;

  },

你可能感兴趣的:(小程序vant-weapp完整时间组件)