The first method, implemented using the PHP class library
/** * Function: Calculates how many years, how many months, and how many days are two dates * param string $date 1[format: 2011-11-5] * param string $date 2[format such as: 2012-12-01] * return array array (' Year ', ' Month ', ' Day '); */function diffdate ($date 1, $date 2) {$datetime 1 = new \datetime ($date 1); $datetime 2 = new \datetime ($date 2); $interval = $datetime 1->diff ($datetime 2); $time [' y '] = $interval->format ('%Y '); $time [' m '] = $interval->format ('%m '); $time [' d '] = $interval->format ('%d '); $time [' h '] = $interval->format ('%H '); $time [' i '] = $interval->format ('%i '); $time [' s '] = $interval->format ('%s '); $time [' a '] = $interval->format ('%a '); Two time difference total days return $time;} # Use instance $sss = Diffdate (' 2015-12-25 12:30:30 ', ' 2015-12-26 15:00:00 ');p rint_r ($sss); # output array ([y] = [m] = 0 [d] = 1 [h] = [i] = [s] = [A] + 1)
The second method, using the function implementation (also in the test ....) )
// 计算两个时间相差(时分秒)$aaa = strtotime('2015-12-26 16:33:33');$bbb = $aaa-time();echo gmstrftime('%Y %m %d %H:%M:%S',$aaa);exit;$left_time = 86400 - time()+strtotime($orderInfo['create_time']);echo:gmstrftime('%H:%M:%S',$left_time);
The above describes how PHP calculates two dates apart, how many months, how many days, including aspects of the content, want to be interested in the PHP tutorial friends helpful.