I've seen plenty of examples of scripts that countdown to a specific date/time... and stop there.
What about counting down to the next Wednesday (and resets to the next Wednesday once this current Wednesday is reached)? More specifically, I'm looking to countdown to Wednesday, 10:30am Japan Standard Time.
Here's what I have so far:
jQuery(document).ready(function($) {
var wednesday = nextWednesday();
wednesday = Math.floor(wednesday / 1000);
var init = setInterval(function() {
var now = new Date();
now = Math.floor(now / 1000);
var counter = wednesday - now;
var seconds = Math.floor(counter % 60);
counter = counter/60;
var minutes = Math.floor(counter % 60);
counter = counter/60;
var hours = Math.floor(counter % 24);
counter = counter/24;
var days = Math.floor(counter);
if (days < 0 && hours < 0 && minutes < 0 && seconds < 0) {
nextWednesday();
}
$('.time').html(days+' days, '+hours+' hours, '+minutes+' minutes, '+seconds+' seconds');
}, 900);
});
function nextWednesday() {
var now = new Date();
var wed = new Date();
wed.setDate(now.getDate() - now.getDay()); // <-- how to make this next Wednesday?
wed.setHours(10);
wed.setMinutes(30);
wed.setSeconds(0);
wed.setMilliseconds(0);
if (wed < now) wed.setDate(wed.getDate() + 7); // <-- Does this accurately set to next Wednesday?
return wed;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="time"></div>
</body>
</html>
I think I'm close, just not quite sure how to make it always be next Wednesday at 10:30am Japan Standard Time.
Thanks!