Heim >Backend-Entwicklung >PHP-Tutorial >PHP计算两个时间戳之差

PHP计算两个时间戳之差

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 09:06:371520Durchsuche

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> $end_time ) {
            <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>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了PHP计算两个时间戳之差,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn