PHP計算兩個時間戳之差
<code><span>/** * 计算两个时间戳之差 *<span> @param</span> $begin_time *<span> @param</span> $end_time *<span> @return</span> array */</span><span><span>function</span><span>timeDiff</span><span>( <span>$begin_time</span>, <span>$end_time</span> )</span>{</span><span>if</span> ( <span>$begin_time</span> < <span>$end_time</span> ) { <span>$starttime</span> = <span>$begin_time</span>; <span>$endtime</span> = <span>$end_time</span>; } <span>else</span> { <span>$starttime</span> = <span>$end_time</span>; <span>$endtime</span> = <span>$begin_time</span>; } <span>$timediff</span> = <span>$endtime</span> - <span>$starttime</span>; <span>$days</span> = intval( <span>$timediff</span> / <span>86400</span> ); <span>$remain</span> = <span>$timediff</span> % <span>86400</span>; <span>$hours</span> = intval( <span>$remain</span> / <span>3600</span> ); <span>$remain</span> = <span>$remain</span> % <span>3600</span>; <span>$mins</span> = intval( <span>$remain</span> / <span>60</span> ); <span>$secs</span> = <span>$remain</span> % <span>60</span>; <span>$res</span> = <span>array</span>( <span>"day"</span> => <span>$days</span>, <span>"hour"</span> => <span>$hours</span>, <span>"min"</span> => <span>$mins</span>, <span>"sec"</span> => <span>$secs</span> ); Log::info(<span>$res</span>); <span>return</span><span>$res</span>; }</code>
以上就介紹了PHP計算兩個時間戳記之差,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。