2017-10-09 91 views
0

如何检查当前时间是否处于休息时间或不使用php?我需要下面的阵列中搜索如果例如当前时间是任何任何破在一系列时间间隔中搜索当前时间

$current = date('Y-m-d H:i:s');

Array 
(
    [0] => Array 
     (
      [break] => 1 
      [start] => 2017-10-10 16:32:00 
      [end] => 2017-10-12 14:54:33 
     ) 

    [1] => Array 
     (
      [break] => 2 
      [start] => 2017-10-16 14:54:33 
      [end] => 2017-10-18 23:55:00 
     ) 

) 
+0

'> && <'操作符可以为你工作。 – urfusion

+0

https://stackoverflow.com/questions/2113940/compare-given-date-with-today,应该对你有用 –

回答

0
foreach ($items as $item) { 
    if ($item->start <= $current && $item->end >= $current) { 
     // Do stuff 
    } 
} 

或...的开始/结束日期之间

$items = array_filter($items, function($item) { 
    return ($item->start <= $current && $item->end >= $current); 
});