Home > Backend Development > PHP Tutorial > php display user friendly time

php display user friendly time

WBOY
Release: 2016-07-25 08:45:05
Original
948 people have browsed it

Within a minute "Just now" Within an hour "* minutes ago" Within today "Today's hour: minutes" Within yesterday "Yesterday's hour: minutes "Greater than 2 days" Year-month-day hour: minutes"

  1. / /Format time
  2. function format_date($beforetime)
  3. {
  4. $time= time() - $beforetime;
  5. $today=strtotime(date("M-d-y",mktime(0,0,0,date("m") ,date("d"),date("Y"))));
  6. if($time <= 60){
  7. return 'just';
  8. }elseif($time>=60 && $time<3600) {
  9. $return=intval($time / 60)." minutes ago";
  10. }else{
  11. if($beforetime>$today){
  12. $return="Today".date("H:i",$beforetime );
  13. }elseif($beforetime<$today && $beforetime>($today-86400)){
  14. $return="Yesterday".date("H:i",$beforetime);
  15. }else{
  16. $return =date("Y-m-d H:i",$beforetime);
  17. }
  18. }
  19. return $return;
  20. }
Copy code

php


Related labels:
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