获取当前时间 YYYY-MM-DD HH:mm:ss:
computed: {
timeDefault() {
let data = new Date();
let hour = data.getHours() < 10 ? "0" + data.getHours() : data.getHours();
let minute = data.getMinutes() < 10 ? "0" + data.getMinutes() : data.getMinutes();
let second = data.getSeconds() < 10 ? "0" + data.getSeconds() : data.getSeconds();
return data.getFullYear()+'-'+(data.getMonth()+1)+'-'+data.getDate()+' '+hour+':'+minute+':'+second;
},
},
月份补0:
export function appendZero(obj) {
if (obj < 10) return '0' + '' + obj;
else return obj;
}
时间转换为HH:MM格式:
export function parsemonth(time) {
if (time === null || time === undefined || time === '' || moment(time).year() <= 1900) {
return '';
}
return moment(time).format('YYYY-MM');
}
时间转换为HH:MM:SS格式:
export function parseTime(time) {
if (time === null || time === undefined || time === '' || moment(time).year() <= 1900) {
return '';
}
return moment(time).format('YYYY-MM-DD');
}
时间转换为YYYY-MM-DD HH:mm:ss格式:
export function parseLongTime(time) {
if (time === null || time === undefined || time === '' || moment(time).year() <= 1900) {
return '';
}
return moment(time).format('YYYY-MM-DD HH:mm:ss');
}
时间转换为YYYY-MM-DD HH:mm格式:
export function parseMiddleTime(time) {
if (time === null || time === undefined || time === '' || moment(time).year() <= 1900) {
return '';
}
return moment(time).format('YYYY-MM-DD HH:mm');
}