
elementplus DateTimePicker 日期范围选择器 设置默认时间范围为当前月的起始时间到结束时间
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element

·
代码如下:
<el-date-picker
v-model="value"
type="datetimerange"
start-placeholder="Start Date"
end-placeholder="End Date"
:default-time="defaultTime"
/>
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'
获取当前月的起始 结束日期
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
}




A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:6 个月前 )
c345bb45
10 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 10 个月前
更多推荐
所有评论(0)