Php calculates the time difference between two timestamps (hours)

Source: Internet
Author: User
Calculate the time difference between the two timestamps. in the past, the actual number of days has been released by the home of Fool, which can be specific to the number of hours. For more information, see. This is the php code specific to the hour.

The code is as follows:


/* Author: Yang yuyangyu@sina.cn */
// Enter two timestamps to calculate the difference value, that is, the number of hours of the difference. if the return value is, the difference between the two input time ranges by 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;
}


Below is the function code js specific to the number of days

The code is 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 = 'date difference'+ Time +'Day! ';} 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.