php对日期时间的格式化(实现多少天前,秒前….)

释放双眼,带上耳机,听听看~!

<?php
header(“Content-type: text/html; charset=utf8”);
date_default_timezone_set(“Asia/Shanghai”); //设置时区
function time_tran($the_time) {
$now_time = date(“Y-m-d H:i:s”, time());
//echo $now_time;
$now_time = strtotime($now_time);
$show_time = strtotime($the_time);
$dur = $now_time – $show_time;
if ($dur < 0) {
return $the_time;
} else {
if ($dur < 60) {
return $dur . ‘秒前’;
} else {
if ($dur < 3600) {
return floor($dur / 60) . ‘分钟前’;
} else {
if ($dur < 86400) {
return floor($dur / 3600) . ‘小时前’;
} else {
if ($dur < 259200) {//3天内
return floor($dur / 86400) . ‘天前’;
} else {
return $the_time;
}
}
}
}
}
}

echo time_tran(“2014-7-8 19:22:01”);
?>

【转自慕课】https://www.imooc.com

PHP

扩展名的本质*.*.*,这种文件你是咋理解的

2022-3-3 15:27:33

PHP

Thinkphp生成验证码与自动验证

2022-3-3 15:30:31

搜索