The PHP implementation was released at precise minutes/hours/days/months ago etc.

WBOY
Release: 2016-07-25 09:12:40
Original
1194 people have browsed it
  1. /*
  2. * Precise time interval function
  3. * $time release time such as 1356973323
  4. * $str output format such as Y-m-d H:i:s
  5. * The number of seconds in half a year is 15552000, and 1 year is 31104000, used here Half a year's time
  6. */
  7. function from_time($time,$str){
  8. isset($str)?$str:$str='m-d';
  9. $way = time() - $time;
  10. $r = '';
  11. if($way < 60){
  12. $r = 'just';
  13. }elseif($way >= 60 && $way <3600){
  14. $r = floor($way/60 ).'minutes ago';
  15. }elseif($way >=3600 && $way <86400){
  16. $r = floor($way/3600).'hours ago';
  17. }elseif($way > =86400 && $way <2592000){
  18. $r = floor($way/86400).'天前';
  19. }elseif($way >=2592000 && $way <15552000){
  20. $r = floor ($way/2592000).'months ago';
  21. }else{
  22. $r = date("$str",$time);
  23. }
  24. return $r;
  25. }
Copy code



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!