这里, 日期选择, 精确到时分秒 的两种不同写法, 最终获取到的数值, 是一样的
<template>
<el-date-picker v-model="params.date" type="datetimerange" range-separator="~" start-placeholder="开始日期"
end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']"
@input="immediUpdate">
</el-date-picker>
<el-date-picker v-model="params.date" type="daterange" range-separator="~" start-placeholder="开始日期"
end-placeholder="结束日期" v-show="dateType=='day'" value-format="yyyy-MM-dd HH:mm:ss"
:default-time="['00:00:00', '23:59:59']" @input="immediUpdate">
</el-date-picker>
</template>
<script>
this.getNowTime();
//处理默认选中当前日期
getNowTime() {
console.log('NNNNNNNNN')
var curDate = (new Date()).getTime();
var dayNum = 3 * 24 * 3600 * 1000;
var threeDays = curDate - dayNum;
// console.log(this.getLocalTime(curDate), this.getLocalTime(threeDays))
var sDay = this.getLocalTime(threeDays)
var end = this.getLocalTime(curDate)
this.params.date = [sDay, end]
console.log(this.params.date)
},
getData(page = 0) {
console.log(this.params)
const load = this.$fns.loading();
requestDevice.deviceStatus({
page: this.page = page,
limit: this.limit,
deviceId: this.deviceId,
deviceType: this.deviceType,
// startTime: this.startTime,
// endTime: this.endTime,
startTime: this.params.date == null ? null : this.params.date[0],
endTime: this.params.date == null ? null : this.params.date[1],
order: "desc"
}).then((res) => {
console.log(res);
load.close();
this.total = res.total
this.tableData = res.data
})
},
add0(m) { return m < 10 ? '0' + m : m },
getLocalTime(nS) {
// return new Date(parseInt(nS)).toLocaleString().replace(/:\d{1,2}$/, ' ');
//shijianchuo是整数,否则要parseInt转换
var time = new Date(nS);
var y = time.getFullYear();
var m = time.getMonth() + 1;
var d = time.getDate();
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
return y + '-' + this.add0(m) + '-' + this.add0(d) + ' ' + this.add0(h) + ':' + this.add0(mm) + ':' + this.add0(s);
},
immediUpdate(e) {
this.$nextTick(() => {
if (e == null) {
this.startTime = '';
this.endTime = '';
}
});
},
</script>