标准时间格式转换
转换时间格式为yyyy-MM-dd hh:mm:ss.
formatDate(date,fmt){
let time = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds(),
'q+': Math.floor((date.getMonth() + 3)/3),
's+': date.getMilliseconds(),
};
if(/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in time) {
if(new RegExp("("+ k +")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (time[k]) : (("00"+ time[k]).substr((""+ time[k]).length)));
}
}
return fmt;
},
使用
const getStartDate = this.formatDate(this.userformData.startDate[0],'yyyy-MM-dd hh:mm:ss')
const getEndDate = this.formatDate(this.userformData.startDate[1],'yyyy-MM-dd hh:mm:ss')