中的兩個時間戳所以現場是,我有一家店在晚上1點開門,晚上10點關門。 對於任何當前時間,我只是想檢查時間戳是否位於商店開放時間和關閉時間之間。比較php
Yeap很簡單,但我不知道爲什麼,我覺得很難。下面的 是我嘗試的一段史詩般的狗屎。
<?php
$t=time(); //for current time
$o = date("Y-m-d ",$t)."01:00:00"; //store open at this time
$c = date("Y-m-d ",$t)."22:00:00"; //store closes at this time
//Yes, its crazy .. but I love echoing variables
echo "current time = ".$t;
echo PHP_EOL;
echo "Start = ".strtotime($o);
echo PHP_EOL;
echo "End = ".strtotime($c);
echo PHP_EOL;
// below condition runs well, $t is always greater than $o
if($t>$o){
echo "Open_c1";
}else{
echo "Close_c1";
}
//Here's where my variable $t, behaves like a little terrorist and proclaims itself greater than $c
if($t<$c){
echo "Open_c2";
}else{
echo "Close_c2";
}
?>
OUTPUT:上phpfiddle
當前時間= 1472765602開始= 1472706000結束= 1472781600 Open_c1 Close_c2
只是一個幫助,爲什麼($ T < $ C)條件爲假。 我錯過了一些很常見的東西,或者犯了一個嚴重的錯誤。
謝謝。
我的壞..我忘了將$ o&$ c轉換爲字符串,並將字符串與日期進行比較。 – Sarge