今天获取当前时间的时候,gpt输出这样的代码,padStart(2, '0')
function getCurrentDateFormatted() {const currentDate = new Date();const month = (currentDate.getMonth() + 1).toString().padStart(2, '0');const day = currentDate.getDate().toString().padStart(2, '0');return `_${month}${day}`;
}const formattedDate = getCurrentDateFormatted();
console.log(formattedDate);
看下MDN对它的解释
有头就有尾