首页 > 后端开发 > php教程 > php返回相对时间,如:20分钟前,3天前

php返回相对时间,如:20分钟前,3天前

WBOY
发布: 2016-07-25 08:43:09
原创
974 人浏览过
  1. function plural($num) {
  2. if ($num != 1)
  3. return "s";
  4. }
  5. function getRelativeTime($date) {
  6. $diff = time() - strtotime($date);
  7. if ($diff return $diff . " second" . plural($diff) . " ago";
  8. $diff = round($diff/60);
  9. if ($diff return $diff . " minute" . plural($diff) . " ago";
  10. $diff = round($diff/60);
  11. if ($diff return $diff . " hour" . plural($diff) . " ago";
  12. $diff = round($diff/24);
  13. if ($diff return $diff . " day" . plural($diff) . " ago";
  14. $diff = round($diff/7);
  15. if ($diff return $diff . " week" . plural($diff) . " ago";
  16. return "on " . date("F j, Y", strtotime($date));
  17. }
复制代码

php


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板