SOURCE

const getCurrentDate = (type,now,splitor="-") => {
	now ??= new Date();
    const dMap={
        'y':now.getFullYear(),
        'm':String(now.getMonth() + 1).padStart(2,0),
        'd':String(now.getDate()).padStart(2,0)
    }
    return dMap[type]||Object.values(dMap).join(splitor);
};

const getCurrentTime = (type,now,splitor=":") => {
	now ??= new Date();
    const dMap={
        'h':now.getHours(),
        'm':String(now.getMinutes()).padStart(2,0),
        's':String(now.getSeconds()).padStart(2,0)
    }
    return dMap[type]||Object.values(dMap).join(splitor);
};

class CustomDate extends Date{
   constructor(){
       super();
   }
   static getCurrentTime=getCurrentTime;
   static getCurrentDate=getCurrentDate;
   
   static getCurrentDateTime=(d=new Date())=>{
       return `${getCurrentDate(d)} ${getCurrentTime(d)}`;
   };
   static getCurrentWeek(){
       const now=new Date();
        const year=now.getFullYear();
        const month=now.getMonth();
        const day=now.getDate();
        const week=now.getDay();
        console.log(day,week)
        const off=day-week;
       return [new Date(year,month,off+1).toLocaleDateString(),new Date(year,month,off+7).toLocaleDateString()];
   }
}

console.log(new CustomDate())
console.log(CustomDate.getCurrentDate())
console.log(CustomDate.getCurrentWeek())
console 命令行工具 X clear

                    
>
console