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