Last active
April 19, 2021 19:21
-
-
Save tjvantoll/9ab79e7a610b314f6e45e15b04b78b18 to your computer and use it in GitHub Desktop.
react-wednesdays.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// var nextEpisode = new Date(2020, 8, 2, 13); | |
var nextEpisode = new Date(2020, 8, 1, 10); | |
var daysSpan = document.querySelector("#countdown-days span"); | |
var hoursSpan = document.querySelector("#countdown-hours span"); | |
var minutesSpan = document.querySelector("#countdown-minutes span"); | |
var secondsSpan = document.querySelector("#countdown-seconds span"); | |
function updateDate() { | |
var today = new Date(); | |
if (today > nextEpisode) { | |
document.querySelector("#countdown").style.display = "none"; | |
document.querySelector("#live-now").style-display = "block"; | |
return; | |
} | |
var diffSeconds = Math.abs(nextEpisode - today) / 1000; | |
var diffMinutes = diffSeconds / 60; | |
var diffHours = diffMinutes / 60; | |
var diffDays = diffHours / 24; | |
var days = Math.floor(diffDays); | |
var hours = Math.floor(diffHours - (days * 24)); | |
var minutes = Math.floor(diffMinutes - (days * 24 * 60) - (hours * 60)); | |
var seconds = 60 - today.getSeconds(); | |
if (seconds === 60) seconds = 0; | |
daysSpan.innerHTML = ("0" + days).slice(-2); | |
hoursSpan.innerHTML = ("0" + hours).slice(-2); | |
minutesSpan.innerHTML = ("0" + minutes).slice(-2); | |
secondsSpan.innerHTML = ("0" + seconds).slice(-2); | |
} | |
updateDate(); | |
setInterval(updateDate, 1000); |
Author
tjvantoll
commented
Sep 10, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment