个人比较喜欢的一个方法,如果有更简单的欢迎评论
const now = new Date();
const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, '0');
const date = now.getDate().toString().padStart(2, '0');
const hours = now.getHours().toString().padStart(2, '0');
const minutes = now.getMinutes().toString().padStart(2, '0');
const seconds = now.getSeconds().toString().padStart(2, '0');
const weekdays = [ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
const week = weekdays[now.getDay()]; //星期
const time = `${hours}:${minutes}:${seconds}` //时分秒
const date = `${year}-${month}-${date} `; //年月日