I'm trying to create a 24 hour sale time for a website. I've figured out how to do this for a daily timer that starts at midnight by taking the current time but I need to be more flexible with this and be able to start it at a random time of the day. The code I've currently got:
<div id="countdown_hours"></div>
<script>
setInterval(function time(){
var d = new Date();
var hours = 24 - d.getHours();
var minutes = 60 - d.getMinutes();
if((minutes + '').length == 1){
minutes = '0' + minutes;
}
var seconds = 60 - d.getSeconds();
if((seconds + '').length == 1){
seconds = '0' + seconds;
}
document.getElementById("countdown_hours").innerHTML =
'<div class="clockcontainer">'
+ '<p>Promo</p>'
+ '<div class="clock">'
+ '<div class="count"><span>'
+ hours
+ '</span> <label> Hours</label> </div>'
+ '<div class="count"><span>'
+ minutes
+ '</span> <label> Minutes</label> </div>'
+ '<div class="count"><span>'
+ seconds
+'</span> <label> Seconds</label> </div>'
+ '</div>'
+ '</div>';
}, 1000);
</script>
So I guess I need to set a variable to my countdown time so var time = 24
for example and then count down from this var time in hours, minutes and seconds. Can anybody point me in the right direction of how to achieve this?