Heim  >  Artikel  >  Backend-Entwicklung  >  如何正确实现PHP显示文章发布时间_PHP教程

如何正确实现PHP显示文章发布时间_PHP教程

WBOY
WBOYOriginal
2016-07-15 13:34:331315Durchsuche

大家都知道,

PHP显示文章发布时间代码示例:

  1.  ?php  
  2. function format_date($dateStr) {  
  3. $limit = time() - strtotime($dateStr);  
  4. $r = "";  
  5. if($limit  60) {  
  6. $r = '刚刚';  
  7. } elseif($limit >= 60 && $limit 
     3600) {  
  8. $r = floor($limit / 60) . '分钟前';  
  9. } elseif($limit >= 3600 && $limit 
     86400) {  
  10. $r = floor($limit / 3600) . '小时前';  
  11. } elseif($limit >= 86400 && $limit 
     2592000) {  
  12. $r = floor($limit / 86400) . '天前';  
  13. } elseif($limit >= 2592000 && $limit 
     31104000) {  
  14. $r = floor($limit / 2592000) . '个月前';  
  15. } else {  
  16. $r = "很久前";  
  17. }  
  18. return $r . "(" . $dateStr . ")";  
  19. }  
  20. echo "发表于:" . format_date
    ("2009-11-25 23:40");  
  21. ?> 

以上这段代码就是PHP显示文章发布时间的具体实现方法介绍。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445990.htmlTechArticle大家都知道, PHP显示文章发布时间代码示例: ?php functionformat_date($dateStr){ $ limit = time ()-strtotime($dateStr); $ r = ; if($limit 60 ){ $ r = '刚刚' ; }e...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn