php两次访问时间,php – 检查当前时间是否介于两次之间,可能会有几天的时间
這比你想象的要容易得多.假設(shè)您有三次,t1,t2和tn分別代表from,to和user time.將這些時間視為六位數(shù)字(從000000到235959)并檢查:
>如果t1和t2出現(xiàn)在午夜邊界的同一側(cè)
>檢查tn是否位于t1和t2之間
>其他
>檢查tn和t1之間是否存在tn
代碼和測試:
function check_time($t1, $t2, $tn) {
$t1 = +str_replace(":", "", $t1);
$t2 = +str_replace(":", "", $t2);
$tn = +str_replace(":", "", $tn);
if ($t2 >= $t1) {
return $t1 <= $tn && $tn < $t2;
} else {
return ! ($t2 <= $tn && $tn < $t1);
}
}
$tests = array(
array("16:00:00", "22:30:00", "15:00:00"),
array("16:00:00", "22:30:00", "16:00:00"),
array("16:00:00", "22:30:00", "22:29:59"),
array("16:00:00", "22:30:00", "22:30:00"),
array("16:00:00", "22:30:00", "23:59:59"),
array("22:30:00", "16:00:00", "22:29:59"),
array("22:30:00", "16:00:00", "22:30:00"),
array("22:30:00", "16:00:00", "15:59:59"),
array("22:30:00", "16:00:00", "16:00:00"),
array("22:30:00", "16:00:00", "17:00:00")
);
foreach($tests as $test) {
list($t1, $t2, $t0) = $test;
echo "$t1 - $t2 contains $t0: " . (check_time($t1, $t2, $t0) ? "yes" : "no") . "\n";
}
// OUTPUT
//
// 16:00:00 - 22:30:00 contains 15:00:00: no
// 16:00:00 - 22:30:00 contains 16:00:00: yes
// 16:00:00 - 22:30:00 contains 22:29:59: yes
// 16:00:00 - 22:30:00 contains 22:30:00: no
// 16:00:00 - 22:30:00 contains 23:59:59: no
// 22:30:00 - 16:00:00 contains 22:29:59: no
// 22:30:00 - 16:00:00 contains 22:30:00: yes
// 22:30:00 - 16:00:00 contains 15:59:59: yes
// 22:30:00 - 16:00:00 contains 16:00:00: no
// 22:30:00 - 16:00:00 contains 17:00:00: no
總結(jié)
以上是生活随笔為你收集整理的php两次访问时间,php – 检查当前时间是否介于两次之间,可能会有几天的时间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php smarty fetch,fet
- 下一篇: 姜和红糖怎么熬?