代码如下:
html
<el-date-picker
v-model="value"
type="datetimerange"
start-placeholder="Start Date"
end-placeholder="End Date"
:default-time="defaultTime"
/>
javascript
const defaultTime: [Date, Date] = [
new Date(2000, 1, 1, 12, 0, 0),
new Date(2000, 2, 1, 8, 0, 0),
] // '12:00:00', '08:00:00'
获取当前月的起始 结束日期
javascript
const getCurrentDate = ():Array<string> =>{
let currentTimeRange = [] as Array<string>;
const currentDate = new Date();
// 获取当前月份
const currentMonth = currentDate.getMonth() + 1; // 月份从 0 开始,所以需要加 1
// 获取当前月份的起始时间
const startTime = `${currentDate.getFullYear()}-${currentMonth
.toString()
.padStart(2, '0')}-01 00:00:00`;
// 获取当前月份的终止时间
const lastDay = new Date(
currentDate.getFullYear(),
currentMonth,
0
).getDate();
const endTime = `${currentDate.getFullYear()}-${currentMonth
.toString()
.padStart(2, '0')}-${lastDay.toString().padStart(2, '0')} 23:59:59`;
currentTimeRange = [startTime,endTime]
//返回当前月的起始 结束日期
return currentTimeRange
}