vue filters 日期格式化
日期格式化
/**
* Parse the time to string
* @param {(Date|string|number)} time
* @param {string} format
* @returns {string}
* {{item.creationTime | momentFormat('YYYY-MM-DD')}}
*/
export function momentFormat(dateTime, format) {
if (arguments.length === 0) {
return dateTime
}
if (!dateTime) { return ''; }
if (!moment(dateTime).isValid()) { return dateTime; }
const cFormat = format || 'YYYY-MM-DD HH:mm:ss'
return moment(dateTime).format(cFormat);
}