Is Time Between Two Other Times?
What I want to do (for example) is change my site's logo on Wednesdays, between 8:00pm, and 2:00am. Technically 2:00am is Thursday morning. So how would I check if the current time is between 8:00pm an开发者_开发技巧d 2:00am on Wednesday?
Well, even easier :
$current_time = strtotime('now');
if ($current_time > strtotime('wednesday this week 8:00pm') && $current_time < strtotime('thursday this week 2:00am')) {
// Special logo
}
Replace strtotime(...)
stuff with time()
to deal with current time.
$date = strtotime('2011-03-24 01:00:00');
if ((date('w', $date) == 3 && date('H', $date) >= 20) ||
(date('w', $date) == 4 && date('H', $date) <= 1)) {
echo "it's time to change logo";
} else {
echo 'hello world';
}
精彩评论