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)));//总相差N小时
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/>";
}
php获取两个时间戳之间相隔多少天多少小时多少分多少秒
猜你喜欢
转载自blog.csdn.net/hanzhuhuaa/article/details/132693763
今日推荐
周排行