personal-website/layouts/shortcodes/footer-timer.html

33 lines
1.2 KiB
HTML
Raw Normal View History

2024-05-03 16:28:31 +02:00
^-^ <a id="inconspicuous-timer-a" href="/images/secret.jpg" ><i id="inconspicuous-timer"></i></a>
2024-05-03 16:26:31 +02:00
<script>
// Set the date we're counting up from
const countUpDate = new Date("Dec 28, 2023 12:34:56").getTime();
const timerElement = document.getElementById("inconspicuous-timer")
function updateHtml() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count up date
var distance = now - countUpDate;
// Time calculations for days, hours, minutes and seconds
var years = Math.floor(distance / (1000 * 60 * 60 * 24 * 365));
var days = Math.floor(distance % (1000 * 60 * 60 * 24 * 365) / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var text = ""
if (years != 0) {
2024-05-03 16:28:31 +02:00
text = years + "y " + days + "d " + hours + "h " + minutes + "m "
2024-05-03 16:26:31 +02:00
} else {
2024-05-03 16:28:31 +02:00
text = days + "d " + hours + "h " + minutes + "m "
2024-05-03 16:26:31 +02:00
}
timerElement.innerHTML = text;
}
updateHtml()
var x = setInterval(updateHtml, 1000);
</script>