PHP calculates a function of two time intervals (hours) _php tips

Source: Internet
Author: User
This is the PHP code that can be specific to the hour
Copy Code code as follows:

/* Author: Yangyu yangyu@sina.cn * *
Enter two timestamps, calculate the difference, that is, the difference of the number of hours, such as the return of 2:10, indicates that the two times entered the difference between 2 hours and 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;
}

here is the specific to the number of days of the function code JS
Copy 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 <strong style= ' color:red ' > ' +time+ ' </strong> days! ';} </script>

Date Difference days Online computing tool

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.