PHP函数,返回多少分钟,多少秒,多少小时前
/** * 将时间转换为几秒前、几分钟前、几小时前、几天前 * @param $in_time 需要转换的时间字符串 * @return string */ public static function timeTran($in_time) { $now_time = time(); $in_time = strtotime($in_time); $dur = $now_time - $in_time; if ($dur < 0) { return $in_time; } if ($dur < 60) { return $dur . ‘秒前‘; } if ($dur < 3600) { return floor($dur / 60) . ‘分钟前‘; } if ($dur < 86400) { return floor($dur / 3600) . ‘小时前‘; } if ($dur < 259200) { // 3天内 return floor($dur / 86400) . ‘天前‘; } else { return $in_time; } }
相关推荐
Greatemperor 2020-07-19
勇往直前 2020-05-17
CloudXli 2020-02-21
GoatSucker 2020-02-09
千锋 2020-01-29
assastor 2020-01-29
89510194 2020-01-18
llwang0 2019-12-28
azhou 2019-12-27
Airuio 2019-12-20
sunnyJam 2019-12-08
wyqwilliam 2019-11-12
Laozizuiku 2019-11-12
zhangpan 2019-11-10
sprintwind 2011-03-23
xianhe0 2010-08-25
Python探路者 2019-06-18