js时间格式化
// formatDate(inDate,"yyyy-MM-dd HH:mm:ss"); 时间戳格式化
export const FormatDate = (dateObj, format) => {
if (!dateObj) {
return "";
}
if (dateObj instanceof Date) {
} else if (!isNaN(dateObj)) {
dateObj = new Date(parseInt(dateObj));
} else {
return "";
}
var o = {
"M+": dateObj.getMonth() + 1, //month
"d+": dateObj.getDate(), //day
"H+": dateObj.getHours(), //hour of day
"m+": dateObj.getMinutes(), //minute
"s+": dateObj.getSeconds(), //second
"q+": Math.floor((dateObj.getMonth() + 3) / 3), //quarter
"S": dateObj.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
(dateObj.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length == 1 ? o[k] :
("00" + o[k]).substr(("" + o[k]).length));
return format;
}

浙公网安备 33010602011771号