日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php两次访问时间,php – 检查当前时间是否介于两次之间,可能会有几天的时间

發(fā)布時(shí)間:2025/4/5 php 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php两次访问时间,php – 检查当前时间是否介于两次之间,可能会有几天的时间 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這比你想象的要容易得多.假設(shè)您有三次,t1,t2和tn分別代表from,to和user time.將這些時(shí)間視為六位數(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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。