const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
(async function() {
let starttime = Date.now();
const seconds = 3 * 1000; // Convert seconds (3) to milliseconds
const endtime = starttime + seconds;
while (starttime < endtime) {
await sleep(1000); // Sleep for 1 second
starttime = Date.now();
console.log(new Date(starttime).toString());
}
})();
/*
run:
Fri Oct 11 2024 09:04:58 GMT+0000 (Coordinated Universal Time)
Fri Oct 11 2024 09:04:59 GMT+0000 (Coordinated Universal Time)
Fri Oct 11 2024 09:05:00 GMT+0000 (Coordinated Universal Time)
*/