I'm creating an update function to show my users when the next update will be available. I'm using the jQuery countdown plugin to show the time. What is a more efficient way to write this?
today = new Date();
todayDay = today.getDate();
todayYear = today.getFullYear();
todayMonth = today.getMonth();
todayMonth ++;
var countTo = "";
// $('#countdown').countdown('12:00:00');
var morningUpdate = new Date();
morningUpdate.setHours(10,0,0,0);
var middayUpdate = new Date();
middayUpdate.setHours(14,0,0,0);
var afternoonUpdate = new Date();
afternoonUpdate.setHours(17,0,0,0);
if(today < afternoonUpdate) {
countTo = "17:00:00";
}
if(today < middayUpdate) {
countTo = "14:00:00";
}
if(today < morningUpdate) {
countTo = "10:00:00";
}
todayString = todayYear + "/" + todayMonth + "/" + todayDay;
console.log(todayString);
var countDownTo = todayString + " " + countTo;
console.log(countDownTo);
console.log("2015/5/13 12:00:00");
$('#clock').countdown(countDownTo, function(event) {
var totalHours = event.offset.totalDays * 24 + event.offset.hours;
$(this).html(event.strftime(totalHours + ' hr %M min %S sec'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://raw.githubusercontent.com/hilios/jQuery.countdown/v2.0.4/src/countdown.js"></script>
<div id="clock"></div>