// import { MessageBox } from 'element-ui';
/**
* 格式化日期
* @param timestamp
* @param formats
* @returns {*}
*/
export function formatDate(timestamp, formats) {
formats = formats || "Y-M-D h:m:s";
var myDate = timestamp ? new Date(timestamp) : new Date();
var year = myDate.getFullYear();
var month = formatDigit(myDate.getMonth() + 1);
var day = formatDigit(myDate.getDate());
var hour = formatDigit(myDate.getHours());
var minute = formatDigit(myDate.getMinutes());
var second = formatDigit(myDate.getSeconds());
var ms1 = myDate.getMilliseconds().toString(); // 获取当前毫秒数
var ms = ms1.length === 1 ? "00" + ms1 : ms1.length === 2 ? "0" + ms1 : ms1;
return formats.replace(/Y|M|D|h|m|s|q/g, function(matches) {
return {
Y: year,
M: month,
D: day,
h: hour,
m: minute,
s: second,
q: ms
}[matches];
});
}
export function formatDigit(n) {
return n.toString().replace(/^(\d)$/, "0$1");
}
01-25
987
01-25
844