//格式化时间
export const formatting=(object,fmt="Y-m-d H:i:s")=>{
const date = new Date(object);
let year = date.getFullYear();
let month = date.getMonth() + 1;
month = month < 10 ? `0${month}` : month;
let day = date.getDate();
day = day < 10 ? `0${day}` : day;
let hours = date.getHours();
hours = hours < 10 ? `0${hours}` : hours;
let minutes = date.getMinutes();
minutes = minutes < 10 ? `0${minutes}` : minutes;
let seconds = date.getSeconds();
seconds = seconds < 10 ? `0${seconds}` : seconds;
let time = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
if(fmt=="Y-m-d"){
time = `${year}-${month}-${day}`;
}
return time;
}
js格式化时间
最新推荐文章于 2023-06-23 10:37:26 发布