php计算登陆时间差
/* 处理显示时间 @param $time datetime类型 @return str */ private function _doTime($time) { if(empty($time)) return; //转为时间搓 $time_diff = time() - strtotime($time); $re_str = ''; switch ($time_diff) { case $time_diff <= 60: $re_str = floor($time_diff) . '秒之前'; break; case $time_diff <= 3600: $re_str = floor($time_diff / 60) . '分之前'; break; case $time_diff <= 3600 * 24: $re_str = floor($time_diff / 3600) . '小时之前'; break; case $time_diff <= 3600 * 24 * 30: $re_str = floor($time_diff / 3600 / 24 ) . '天之前'; break; case $time_diff <= 3600 * 24 * 30 * 12: $re_str = floor($time_diff / 3600 / 24 / 30 ) . '个月以前'; break; default: $re_str = floor($time_diff / 3600 / 24 / 30 / 12) . '年以前'; break; } return $re_str; }