我有問題檢測到商店在午夜後仍然開放或關閉。午夜時間問題
週二($weekday = 2
),從下午6點店開到凌晨1:30(午夜後)
假設當前時間是上午01時05分
$weekday = 2;
//Convert current time to minutes (01:05)
$currentTime = ($weekday - 1) * 1440 + "01" * 60 + "05";
//Current Week Day
$shopOpenTime = "18:00";
$shopCloseTime = "01:30";
$open = explode(':', $shopOpenTime);
$close = explode(':', $shopCloseTime);
//Convert to Minutes;
$MinutesOpen = (($weekday - 1) * 1440) + ($open[0] * 60 + $open[1]);
$MinutesClose = (($weekday - 1) * 1440) + ($close[0] * 60 + $close[1]);
if ($MinutesClose < $MinutesOpen)
$MinutesClose += 60 * 24;
if (($currentTime >= $MinutesOpen) && ($currentTime < $MinutesClose)) {
echo "Shop Is Open";
} else {
echo "Shop Is Close";
}
什麼是解決這個問題的解決問題?
每天,店鋪開/關時間可能會有所不同。例如:星期一18:00至23:30,星期二11:00至22:00,星期五13:00至01:00(午夜後)。那麼解決方案是什麼? –