在我的網站上,我輸入的格式爲TITLE#HH:MM-HH:MM#LOCATION
。我可以用explode("#",...
輕鬆地將它分成3個不同的數組鍵,並顯示數據,但現在我正在創建一個函數來返回當前時間戳是否在「HH:MM-HH:MM」內。查看時間是否在格式範圍內HH:MM-HH:MM
HH:MM-HH:MM格式爲12:20-13:10
,其中第一次是事件的開始時間,第二次是事件結束的時間。我試圖檢測頁面加載的時間和調用time()
是否在12:20-13:10之內。
我該怎麼做呢?我試圖創建一些代碼,但我不知道如何完成這個乾淨。
謝謝!
UPDATE -
$tEvent = explode("-", $arr[1]);
$now = new DateTime(date("Y-m-d H:i:s",$time), new DateTimeZone('America/Detroit'));
$start = new DateTime($tEvent[0], new DateTimeZone('America/Detroit'));
$end = new DateTime($tEvent[1], new DateTimeZone('America/Detroit'));
if ($now->format('U') >= $start->format('U') && $now->format('U') <= $end->format('U')) {
//within time
}
即使只是以相同的格式格式化當前時間,然後進行字符串比較也可以在這裏工作... – CBroe 2014-08-29 23:48:38
那麼我該怎麼做呢? @Cbroe – 9kv 2014-08-30 00:10:12
通過您的個人資料自稱「PHP開發人員」,您需要問...? http://php.net/manual/en/function.date.php – CBroe 2014-08-30 00:25:58