完整时间选择器
<van-datetime-picker
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;
},