Is Time Between Two Other Times?

前端 未结 2 809
时光取名叫无心
时光取名叫无心 2021-01-12 03:59

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 curr

相关标签:
2条回答
  • 2021-01-12 04:30

    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';
    }
    
    0 讨论(0)
  • 2021-01-12 04:38

    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
    }
    
    0 讨论(0)
提交回复
热议问题