Countdown to multiple update times each day 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 &lt; afternoonUpdate) {
 countTo = "17:00:00";
}

if(today &lt; middayUpdate) {
    countTo = "14:00:00";
}

if(today &lt; 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'));
});
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="https://raw.githubusercontent.com/hilios/jQuery.countdown/v2.0.4/src/countdown.js"&gt;&lt;/script&gt;
&lt;div id="clock"&gt;&lt;/div&gt;
You don't need to create Date object for each day time case (morning/midday/afternoon) since you don't actually use any date component except hour. So you only need to extract current hour from today and define range it belong to.

var today = new Date();
var hour = today.getHours();
hour = hour &lt; 10? 10 : hour &lt; 14? 14 : hour &lt; 17? 17 : 0;
var countDownTo = [today.getFullYear(), today.getMonth()+1, today.getDate()].join('/')+ (hour? hour+':00:00' : '');
...