xxxxxxxxxx
27
let christmas;
let timer;
function setup() {
createCanvas(400, 200);
christmas = new Date("2023-12-25T00:00:00");
timer = select('#timer');
}
function draw() {
background(220);
let now = new Date();
let timeRemaining = christmas - now;
if (timeRemaining > 0) {
let days = Math.floor(timeRemaining / (1000 * 60 * 60 * 24));
let hours = Math.floor((timeRemaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000);
let timerString = `${days}d ${hours}h ${minutes}m ${seconds}s`;
timer.html(timerString);
} else {
timer.html("Merry Christmas!");
}
}