Home  >  Article  >  Backend Development  >  How to correctly implement PHP to display article publishing time_PHP tutorial

How to correctly implement PHP to display article publishing time_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:34:331314browse

As we all know,

PHP display article publishing time code example:

  1. < ?php
  2. function format_date($dateStr) {
  3. $limit = time() - strtotime($dateStr);
  4. $r = "" ; 🎜>
  5. 60
  6. ) { $r = 'just'
  7. ;
  8. } elseif($limit >= 60 && $limit
  9. < 3600
    ) { $r = floor
  10. ($limit / 60) . 'minutes ago';
  11. } elseif($limit >= 3600 && $limit
  12. < 86400
    ) { $r = floor
  13. ($limit / 3600) . 'hours ago';
  14. } elseif($limit >= 86400 && $limit
  15. < 2592000
    ) { $r = floor
  16. ($limit / 86400) . 'days ago';
  17. } elseif($limit >= 2592000 && $limit
  18. < 31104000
    ) { $r = floor
  19. ($limit / 2592000) . 'months ago' ;
  20. } else { $r =
  21. "A long time ago"
  22. ;
  23. } return $r . "(" . $dateStr . ")"; }
  24. echo "Posted on: " . format_date
  25. (" 2009-11-25 23:40");
  26. ?>
  27. The above code is an introduction to the specific implementation method of displaying the article publishing time in PHP.
  28. www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445990.htmlTechArticleAs we all know, PHP code example for displaying article publishing time: ?php functionformat_date($dateStr){ $ limit = time ()-strtotime($dateStr); $ r = ; if($limit 60 ){ $ r = 'just' ; }e...
Statement:
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