//格式化时间字符串
getFormateTime(time) {
if (time) {
const formateTime =
typeof time === "string" && time.indexOf("T") === -1
? new Date(time.replace(/-/g, "/"))
: new Date(time);
const year = formateTime.getFullYear();
const month =
formateTime.getMonth() + 1 < 10
? "0" + (formateTime.getMonth() + 1)
: formateTime.getMonth() + 1;
const date =
formateTime.getDate() < 10
? "0" + formateTime.getDate()
: formateTime.getDate();
const hour =
formateTime.getHours() < 10
? "0" + formateTime.getHours()
: formateTime.getHours();
const min =
formateTime.getMinutes() < 10
? "0" + formateTime.getMinutes()
: formateTime.getMinutes();
const sec =
formateTime.getSeconds() < 10
? "0" + formateTime.getSeconds()
: formateTime.getSeconds();
return `${year}-${month}-${date} ${hour}:${min}:${sec}`;
} else {
return "";
}
},
js: 日期时间格式化
最新推荐文章于 2024-05-21 10:56:13 发布