Does anyone have an idea how to make a countdown ticker that shows the hours and mins left until a perticular time of day and on a weekend (Sat and Sun) the time left until 16:30 on Monday. It would need to reset @ 16:30 everyday except the weekend days.
This has got me stumpped and re开发者_运维技巧ally could do with some pointers.
Thanks, B.
If you want the page to count down every second, rather than only on refresh, you should use JavaScript. There are many examples out there, and others can be found using google by searching for Javascript Countdown
If you wanted to do it in PHP, the best way is to use mktime() to get the unix timestamp of when the time ends, and the value from time().
Find the difference, and then you can calculate the time left:
$diff = mktime(...) - time();
$days = floor($diff/60/60/24);
$hours = floor(($diff - $days*60*60*24)/60/60);
etc.
EDIT
Javascript...
Basic idea of the date object
var date = new Date(); //gets now
var weekday = date.getDay(); //gets the current day
//0 is Sunday. 6 is Saturday
if ( weekday == 0 ){
date.setTime()(date.getTime()+60*60*24); //increase time by a day
}
if ( weekday == 6 ){
date.setTime()(date.getTime()+60*60*24*2); //increase time by two days
}
//need to check if we have already passed 16:30,
if ( ( date.getHours() == 16 && date.getMinutes() > 30 ) || date.getHours() > 16){
//if we have, increase the day
date.setTime()(date.getTime()+60*60*24)
}
date.setHours(16);
date.setMinutes(30);
//now the date is the time we want to count down to, which we can use with a jquery plugin
Would be JQUery also a solution? Because there are several plugins avalaible which are showing a countdown. With some additional code you could easily calculate the time till the next monday, 4:30 pm.
精彩评论