i'm trying make count down timer counts down couple different hours depending on time of day.
here's how i've tried set function time. if before 14.00, count down 14.00 , if it's after 14.00, count down 20.00. after 20.00, show count down 14.00 tomorrow.
ive tried set target time this, setting date "tomorrow @ 14.00" cant work.
var target_date = new date(); var currentdate = new date(); if (currentdate.gethours() > 0 && currentdate.gethours() < 14) { target_date.sethours(14,0,0,0); } else if (currentdate.gethours() > 14 && currentdate.gethours() < 20) { target_date.sethours(20,0,0,0); } else { target_date.setdate(currentdate.getdate()+1).sethours(16,0,0,0); // if 20-24, count down tomorrow @ 14.00 }
the rest of script count down is
var days, hours, minutes, seconds; var countdown = document.getelementbyid("countdown"); setinterval(function () { var current_date = new date().gettime(); var seconds_left = (target_date - current_date) / 1000; days = parseint(seconds_left / 86400); seconds_left = seconds_left % 86400; hours = parseint(seconds_left / 3600); seconds_left = seconds_left % 3600; minutes = parseint(seconds_left / 60); seconds = parseint(seconds_left % 60); countdown.innerhtml = hours + "t " + minutes + "m"; }, 1000)};
target_date.setdate(currentdate.getdate()+1).sethours(16,0,0,0);
setdate()
method doesn't return date
object, sequence wouldn't work
you should write
target_date.setdate(currentdate.getdate()+1); target_date.sethours(16,0,0,0);
Comments
Post a Comment