PHP calculates the function of hours of the time between two timestamps
- 2020-03-31 20:04:46
- OfStack
This is hour-by-hour PHP code
The following is the day specific function code js
(link: http://tools.jb51.net/tools/riqi.asp)
//Enter two timestamps to calculate the difference, which is the number of hours apart. If you return 2:10, the difference between the two input times is 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;
}
The following is the day specific function code js
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 = ' Difference between two dates <strong style="color:red">'+time+'</strong> Day! ';}</script>
(link: http://tools.jb51.net/tools/riqi.asp)