Maison >développement back-end >tutoriel php >PHP计算两个时间戳之差

PHP计算两个时间戳之差

WBOY
WBOYoriginal
2016-07-29 09:06:371514parcourir

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教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn