장면이 있으므로 밤에 새벽 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";
}
?>
출력 : phpfiddle에
현재 시간 = 1,472,765,602 시작 = 1,472,706,000 끝 = 1,472,781,600 Open_c1 Close_c2
그냥 ($ t < $의 C) 조건이 거짓 이유를 하나 도움. 나는 아주 흔한 것을 놓치거나 심각한 실수를 저질렀다.
감사합니다.
나쁜 ... $ o & $ c를 (를) 문자열로 변환하는 것을 잊어 버렸고 문자열과 날짜를 비교했습니다. – Sarge