提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
代码如下(示例):
<template> <div>开始</div> <DatePicker type="datetime" format="yyyy-MM-dd HH:mm:00" :editable="false" style="width: 200px" @on-change="startTime" :options="startOption" v-model="kaishiTime" ></DatePicker> </div> <div class="you"> <div>结束</div> <DatePicker type="datetime" confirm format="yyyy-MM-dd HH:mm:00" :editable="false" @on-ok="handleOk" @on-change="stopTime" style="width: 200px" :options="endOption" v-model="jieshuTime" ></DatePicker> </div> </template> data() { return { kaishiTime: "", jieshuTime: "", startOption: { // 指定开始限制时间 disabledDate(date) { // 获取选择面板每一个日期的时间戳 const time = date.getTime(); // 获取当前时间戳 const curTime = new Date().getTime(); // 获取三天前的时间戳 const kaishiTime = curTime - 3 * 3600 * 24 * 1000; // 当日期选择面板的日期小于startDate ,或者大于curTime 时,返回true,返回true则不可选 if (time < kaishiTime || time > curTime) { return true; } }, }, endOption: { // 指定终止日期 disabledDate(date) { // 获取选择面板每一个日期的时间戳 const time = date.getTime(); // 获取当前时间戳 const curTime = new Date().getTime(); // 获取三天前的时间戳 const jieshuTime = curTime - 3 * 3600 * 24 * 1000; // 当日期选择面板的日期小于startDate ,或者大于curTime 时,返回true,返回true则不可选 if (time < jieshuTime || time > curTime) { return true; } }, }, } } methods:{ //点击开始时间 startTime(a) { this.videos.startTime = a; }, //点击结束时间 stopTime(a) { this.videos.stopTime = a; // 获取选择面板每一个日期的时间戳 const data = new Date(a); const time1 = data.getTime(); // 获取当前时间戳 const currTime = new Date().getTime(); const current = new Date(currTime); console.log(currTime, "当前时间戳"); // const b = currTime + 3 * 3600 * 24 * 1000; const c = (new Date(new Date().setHours(0, 0, 0, 0)) / 1000) * 1000; //当天0点时间戳 if (time1 < c && a.slice(-8) === "00:00:00") { a = a.slice(0, -8) + "23:59:00"; this.jieshuTime = a; } else if(a.slice(-8) === "00:00:00") { const Y = current.getFullYear() + "-"; const M = (current.getMonth() + 1 < 10 ? "0" + (current.getMonth() + 1) : current.getMonth() + 1) + "-"; const D = current.getDate() + " "; const h = current.getHours() + ":"; const m = current.getMinutes() + ":"; this.jieshuTime=Y+M+D+h+m+'00';//拼接 } }, }
图片:
总结
完成!