Home Backend Development PHP Tutorial PHP calculates the difference between two timestamps

PHP calculates the difference between two timestamps

Jul 29, 2016 am 09:06 AM
time

PHP calculates the difference between two timestamps

<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> &lt; <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> =&gt; <span>$days</span>, <span>"hour"</span> =&gt; <span>$hours</span>, <span>"min"</span> =&gt; <span>$mins</span>, <span>"sec"</span> =&gt; <span>$secs</span> );
        Log::info(<span>$res</span>);
        <span>return</span><span>$res</span>;
    }</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces how PHP calculates the difference between two timestamps, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Monotonic clock processing of time package Monotonic clock processing of time package Aug 04, 2023 pm 05:45 PM

Monotonic clock processing of time package

How to use Java8 Time API How to use Java8 Time API Apr 28, 2023 pm 12:25 PM

How to use Java8 Time API

How to obtain and convert time in Python time module How to obtain and convert time in Python time module May 13, 2023 pm 12:19 PM

How to obtain and convert time in Python time module

What is the difference and usage between time and datetime in python What is the difference and usage between time and datetime in python May 02, 2023 am 11:01 AM

What is the difference and usage between time and datetime in python

How to solve 'undefined: time.After' error in golang? How to solve 'undefined: time.After' error in golang? Jun 25, 2023 pm 05:28 PM

How to solve 'undefined: time.After' error in golang?

Use the PHP function 'time' to return the current UNIX timestamp Use the PHP function 'time' to return the current UNIX timestamp Jul 25, 2023 pm 04:42 PM

Use the PHP function 'time' to return the current UNIX timestamp

Qubetics: A New Standard in Cross-Border Payments and Digital Asset Tokenization Qubetics: A New Standard in Cross-Border Payments and Digital Asset Tokenization Oct 25, 2024 pm 04:38 PM

Qubetics: A New Standard in Cross-Border Payments and Digital Asset Tokenization

What are the methods of the time module in Python? What are the methods of the time module in Python? May 26, 2023 am 11:12 AM

What are the methods of the time module in Python?

See all articles