每秒输出格式化的当前时间
setInterval(() => { const now = new Date(); const hours = now.getHours().toString(); const minutes = now.getMinutes().toString(); const seconds = now.getSeconds().toString(); console.log( `${hours.padStart(2, 0)}:${minutes.padStart(2, 0)}:${seconds.padStart( 2, 0 )}` ); }, 1000);