Difference between revisions of "Widget:Countdown"

From Octopath Traveler Speedruns
Jump to navigation Jump to search
Line 1: Line 1:
<span><!--{$time}--> ET</span><br />
<span><!--{$time}--> ET</span><br />
<span id="countdown">-1d -1h -1m -1s</span>
<span id="countdown">?</span>


<script>
<script>
Line 31: Line 31:
   if (days > 0) {
   if (days > 0) {
     document.getElementById("countdown").innerHTML = "(In about " + days + " days and " + hours + " hours)";
     document.getElementById("countdown").innerHTML = "(In about " + days + " days and " + hours + " hours)";
   } else if (days < 0) {
   } else if (days <= 0) {
     document.getElementById("countdown").innerHTML = "(In about " + hours + " hours and " + minutes + " minutes)";
     document.getElementById("countdown").innerHTML = "(In about " + hours + " hours and " + minutes + " minutes)";
   } else if (distance < 0) {
   } else if (distance < 0) {

Revision as of 05:06, 27 January 2019

ET
?

<script> // Modified version of https://www.w3schools.com/howto/howto_js_countdown.asp

// Conversion from Eastern Time to UTC var easternTimeOffset = 5 * 60 * 60000; if () {

 var easternTimeOffset = 4 * 60 * 60000;

}

var rawDateTimeET = new Date("").getTime(); var countDownDateUTC = rawDateTimeET + easternTimeOffset;

// Update the count down every 1 second var x = setInterval(function() {

 // Get the users date and time and convert to UTC
 var rawNow = new Date();
 var nowUTC = rawNow.getTime() + (rawNow.getTimezoneOffset() * 60000);
 // Find the distance between now and the count down date
 var distance = countDownDateUTC - nowUTC;
 // Time calculations for days, hours, minutes
 var days = Math.floor(distance / (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));
 // Display the result in the element with id="countdown"
 if (days > 0) {
   document.getElementById("countdown").innerHTML = "(In about " + days + " days and " + hours + " hours)";
 } else if (days <= 0) {
   document.getElementById("countdown").innerHTML = "(In about " + hours + " hours and " + minutes + " minutes)";
 } else if (distance < 0) {
   clearInterval(x);
   document.getElementById("countdown").innerHTML = "The race has ended.";
 }

}, 1000); </script>