为了账号安全,请及时绑定邮箱和手机立即绑定

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

标签:
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");
?>

点击查看更多内容
3人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消