<?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人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦