/**
* 格式化时间
* @param {String|Number|Date} fdate 欲格式化的时间,可以是时间戳、时间文本、Date对象
* @param {Object} formatStr 格式,如:y-m-d h:i:s
*/
formatDate: function (fdate = new Date(), formatStr = "y-m-d h:i") {
if (!fdate) {
return "";
}
var fTime;
if (fdate instanceof Date) {
fTime = fdate;
} else if (parseInt(fdate) != NaN) {
fTime = new Date(parseInt(fdate));
} else if (fdate instanceof String) {
if (~fdate.indexOf(".")) {
fdate = fdate.substring(0, fdate.indexOf("."));
}
fdate = fdate.toString().replace("T", " ").replace(/\-/g, "/");
}
var fStr = "ymdhis";
var month = fTime.getMonth() + 1;
var day = fTime.getDate();
var hours = fTime.getHours();
var minu = fTime.getMinutes();
var second = fTime.getSeconds();
month = month < 10 ? "0" + month : month;
day = day < 10 ? "0" + day : day;
hours = hours < 10 ? "0" + hours : hours;
minu = minu < 10 ? "0" + minu : minu;
second = second < 10 ? "0" + second : second;
var formatArr = [
fTime.getFullYear().toString(),
month.toString(),
day.toString(),
hours.toString(),
minu.toString(),
second.toString(),
];
for (var i = 0; i < formatArr.length; i++) {
formatStr = formatStr.replace(fStr.charAt(i), formatArr[i]);
}
return formatStr;
},