php获取两个时间戳之间相隔多少天多少小时多少分多少秒
public function time_cha()
{
$s_date ="2015-12-12 16:00:00";
$e_date ="2016-12-13 18:00:00";
$cha = strtotime($e_date)-strtotime($s_date);
$year = floor((strtotime($e_date)-strtotime($s_date)) / (31536000));
echo "1、相差年数:".$year." 年<br/><br/>";
$month = floor(($cha - $year * 31536000) / (2592000));
$month_total = floor($cha / 2592000);
echo "2、相差月数:".$month." 月<br/><br/>";
echo "3、相差月数:".$month_total." 月<br/><br/>";
$day_total = floor((strtotime($e_date)-strtotime($s_date))/86400);
echo "4、相差总天数:".$day_total." 天<br/><br/>";
$hour = floor((strtotime($e_date)-strtotime($s_date))%86400/3600);
$hour_total = floor((strtotime($e_date)-strtotime($s_date)));
echo "5、相差小时数:".$hour." 小时<br/><br/>";
echo "6、相差总小时数:".$hour_total." 小时<br/><br/>";
$minute = floor((strtotime($e_date)-strtotime($s_date))%86400/60);
$minute_total = floor((strtotime($e_date)-strtotime($s_date))/60);
echo "7、相差分钟数:".$minute."分钟<br/><br/>";
echo "8、相差总分钟数:".$minute_total."分钟<br/><br/>";
$second = floor((strtotime($e_date)-strtotime($s_date))%86400%60);
$second_total = floor((strtotime($e_date)-strtotime($s_date)));
echo "9、相差秒数:".$second." 秒<br/><br/>";
echo "10、相差总秒数:".$second_total." 秒<br/><br/>";
}
|