2

我在这里找到了这个片段。

$resttimefrom = 50000; // 5am
$resttimeto   = 170000; // 5pm
$currentTime  = (int) date('Gis'); // time now

if ($currentTime > $resttimefrom && $currentTime < $resttimeto)
{
  // its before 5pm lets do something
}
else
{
  // after 5pm sorry
}

这工作得很好,但我想限制它的日期也为我正在工作的网站我希望它检查时间戳如果交付 = 明天然后他们必须在前一天下午 5 点之前取消订单。

4

2 回答 2

2
$timestamp = time();

$date = date("Y-m-d", $timestamp);
$time = date("G", $timestamp);

$tomorrow = date('Y-m-d', strtotime('tomorrow'));

if ($date == $tomorrow && $time > 5 && $time < 17) {
    // It is in-between 5am and 5pm tomorrow.
}
于 2012-05-09T08:57:28.070 回答
0
if (time() >= strtotime(date('Y-m-d', time()).' 5:00:00') && time() <= strtotime(date('Y-m-d', time()).' 17:00:00'))    {
    //  today between 5AM and 5PM
}
    else {

    }
于 2012-05-09T08:57:52.263 回答