PHP時間比較

2022-09-14 23:33:22 字數 492 閱讀 3665

判斷系統時間是否在某個時間段內

$timesolt = explode('|', $obj['timeslot']);

$start_time = strtotime($timesolt[0]);

$end_time = strtotime($timesolt[1]);

//獲取系統時間的時分秒時間戳

$x = strtotime(date('h:i:s'));

//對比時間戳查詢當前時間是否在允許時間段內

if(!($x

< $end_time && $x > $start_time

))

strtotime:將某個指定時間段轉換為時間戳:不填年月日會預設為當日

如:strtotime('14:00:00')會顯示為當日下午兩點的時間戳

date:獲取指定格式的時間y:m:d h:i:s

mysql時間比較

時間比較 當前時間是否在某個時間段之內 是否在create time 5天之內 select from message detail where unix timestamp now between unix timestamp create time and unix timestamp crea...

NSDate 時間比較

由 nsdate 轉換為 nsstring nsdateformatter dateformatter nsdateformatter alloc init dateformatter setdateformat yyyy mm dd hh mm ss nsstring strdate datefo...

NSDate 時間比較

由 nsdate 轉換為 nsstring nsdateformatter dateformatter nsdateformatter alloc init dateformatter setdateformat yyyy mm dd hh mm ss nsstring strdate datefo...