2017-10-09 89 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); 
});