PHP は、2 つの日付間の時差/日数、時間、分、秒を計算します。
function?timediff(?$begin_time<🎜) >,?$end_time?)?{?
????if?(? $begin_time?$end_time?)?{?????????? $starttime?=?$begin_time;?????????? $endtime?=?$end_time;?????}?else?{? ????????? $starttime? =?$end_time;?????????? $endtime?=?$begin_time;?????}? ???? $timediff?=?$endtime?-?$starttime;????? $days? =?intval(?$timediff?/?86400?);????? $remain?=?$timediff?%?86400;????? $hours?=?intval(?$remain?/?3600?);????? $remain?=?$remain?%?3600;????? $mins?=?intval(?$remain?/?60?);????? $secs?=?$remain?%?60;????? $res?=?array(?<🎜) >"日"?=>?$days,?"時間"?=> ?$時間,?"分"?=>?$分,?"秒"?=>?$secs?);?????return? $res;?}? //========?インスタンスの使用法========? $timediff? =?timediff(?strtotime(?"2011-10-28"?),?strtotime(?"2011-10-29"?)?);? print_r(?$timediff?);? ?> |