友好的显示时间 PHP端
2016-07-15 14:56
246 查看
/** * 显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前, 如果超过1年, 就直接显示具体时间 * * @param int $inputTimestamp UnixTimestamp * @param string $overflowTimeFormat 超过3天的时间显示格式 * * @return string */ static public function timeAgo($inputTimestamp,$overflowTimeFormat = 'Y/m/d H:i') { if (empty($inputTimestamp) || !is_numeric($inputTimestamp) || !$inputTimestamp) { return ''; } $d = time() - $inputTimestamp; if ($d < 0) { return ''; } else { if ($d < 60) { return $d . '秒前'; } else { if ($d < 3600) { return floor($d / 60) . '分钟前'; } else { if ($d < 86400) { return floor($d / 3600) . '小时前'; } else { if ($d < 259200) {//3天内 return floor($d / 86400) . '天前'; } else { return date($overflowTimeFormat,$inputTimestamp); } } } } } }
相关文章推荐
- php webservice 可能存在的坑
- PHP静态变量和全局变量的区别
- 搞不清FastCgi与PHP-fpm之间是个什么样的关系
- ATOM基础教程一atom-autocomplete-php配置(14)
- sublime 直接运行php代码
- 【框架】JitPack---如何拥有自己的动态库
- php安装imagick扩展
- php 时间加减
- 【旧代码整理】/project/library/function.php 基本function部分
- PHP 给当前时间加日期
- php Logs类
- laravel excel安装使用,导入(读)导出(数据写入文件)
- 新浪微博LAMP性能优化之路 - PHP性能优化
- 【译】PHP中的Session及其一些安全措施
- 自定义PHP页面跳转函数redirect($url, $time = 0, $msg = '')
- NULL和空是两个概念的原因
- htpasswd 详解
- php中return exit() die()的区别
- php访问url的四种方式
- PHP类的属性不能被赋值为变量的原因