PHP calculates the function hours of the time interval between two timestamps

Source: Internet
Author: User
This is a PHP code that can be specific to hours.

Copy the Code code as follows:


/* Author: Yangyu yangyu@sina.cn */
Enter two timestamp, calculate the difference, that is, the number of hours of difference, such as return 2:10, that is, the two time difference between the input 2 hours 10 minutes
function Hours_min ($start _time, $end _time) {
if (Strtotime ($start _time) > Strtotime ($end _time)) List ($start _time, $end _time) = Array ($end _time, $start _time);
$sec = $start _time-$end _time;
$sec = round ($sec/60);
$min = Str_pad ($sec%60, 2, 0, str_pad_left);
$hours _min = Floor ($sec/60);
$min! = 0 && $hours _min. = ': '. $min;
return $hours _min;
}


The following is a specific to the number of days of the function code JS

Copy the Code code as follows:


function Get_date_different () {
var _date_1 = document.getElementById (' date1 '). Value.replace (/(^\s*) | ( \s*$)/g, ");
var _date_2 = document.getElementById (' Date2 '). Value.replace (/(^\s*) | ( \s*$)/g, ");
_date_1 = new Date (_date_1);
_date_2 = new Date (_date_2);
var days= _date_2.gettime ()-_date_1.gettime ();
var time = parseint (days/(1000 * 60 * 60 * 24));
document.getElementById (' content '). InnerHTML = ' Two date difference ' +time+ ' days! ';}


Date Difference days Online calculation tool

The above describes the PHP calculation of two time intervals between the function hours, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.