Copie-colle ce code entre les balises <body> de ta page
Le javascript ci-dessous te permet de faire fonctionner ton timer. Tu peux modifier la date comme bon te semble.
Variante 01 - Format "00:00:00:00"
<script>
// MODIFIEZ LA DATE DE FIN ICI (format ISO 8601)
const endDate = new Date('2025-12-31T23:59:59'); // Exemple : 31 Décembre 2025 à 23:59:59
function updateTimer() {
const now = new Date();
const diff = endDate - now;
if (diff <= 0) {
document.getElementById('timer').textContent = '00:00:00:00';
clearInterval(intervalId);
return;
}
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
const hours = Math.floor((diff / (1000 * 60 * 60)) % 24);
const minutes = Math.floor((diff / (1000 * 60)) % 60);
const seconds = Math.floor((diff / 1000) % 60);
document.getElementById('timer').textContent =
String(days).padStart(2, '0') + ':' +
String(hours).padStart(2, '0') + ':' +
String(minutes).padStart(2, '0') + ':' +
String(seconds).padStart(2, '0');
}
// Mise à jour toutes les secondes
updateTimer();
const intervalId = setInterval(updateTimer, 1000);
</script>
Variante 02 - Format "00j 00h 00min 00sec"
<script>
// MODIFIEZ LA DATE DE FIN ICI (format ISO 8601)
const endDate = new Date('2025-12-31T23:59:59'); // Exemple : 31 Décembre 2025 à 23:59:59
function updateTimer() {
const now = new Date();
const diff = endDate - now;
if (diff <= 0) {
document.getElementById('timer').textContent = '00j 00h 00min 00sec';
clearInterval(intervalId);
return;
}
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
const hours = Math.floor((diff / (1000 * 60 * 60)) % 24);
const minutes = Math.floor((diff / (1000 * 60)) % 60);
const seconds = Math.floor((diff / 1000) % 60);
document.getElementById('timer').textContent =
String(days).padStart(2, '0') + 'j ' +
String(hours).padStart(2, '0') + 'h ' +
String(minutes).padStart(2, '0')+ 'min ' +
String(seconds).padStart(2, '0')+ 'sec';
}
// Mise à jour toutes les secondes
updateTimer();
const intervalId = setInterval(updateTimer, 1000);
</script>
Tutoriel Vidéo