推荐直接使用element日期选择器组件内的属性format
// template
<el-time-picker
is-range
arrow-control
v-model="form.date"
range-separator="至"
start-placeholder="开始时间"
end-placeholder="结束时间"
placeholder="选择时间范围"
></el-time-picker>
// script
console.log(this.form.date[0],this.form.date[1])
开始时间
conststartTime=
conststr1=this.form.date[0]
constdate1=newDate(str1)
consttime=`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}}`
varhour1=date1.getHours()
hour1=hour1<10?'0'+hour1:hour1
varminute1=date1.getMinutes()
minute1=minute1<10?'0'+minute1:minute1
varsecond1=date1.getSeconds()
second1=second1<10?'0'+second1:second1
consttime1=hour1+':'+minute1+':'+second1
结束时间
conststr2=this.form.date[1]
constdate2=newDate(str2)
varhour2=date2.getHours()
hour2=hour2<10?'0'+hour2:hour2
varminute2=date2.getMinutes()
minute2=minute2<10?'0'+minute2:minute2
varsecond2=date2.getSeconds()
second2=second2<10?'0'+second2:second2
consttime2=hour2+':'+minute2+':'+second2
console.log(time1,time2)