How to correctly implement PHP display article release time _ PHP Tutorial

Source: Internet
Author: User
How to correctly display the article release time in PHP. As we all know, PHP shows an example of the release time code :? Phpfunctionformat_date ($ dateStr) {$ limittime ()-strtotime ($ dateStr); $ r; if ($ limit60) {$ r just now;} e everyone knows,

PHP shows the article release time code example:

  1. <? Php
  2. Function format_date ($ dateStr ){
  3. $ Limit = time ()-strtotime ($ dateStr );
  4. $ R = "";
  5. If ($ limit< 60){
  6. $ R = 'gang ';
  7. } Elseif ($ limit>= 60 & $ limit
    < 3600){
  8. $ R = floor ($ limit/60). 'minute ago ';
  9. } Elseif ($ limit>= 3600 & $ limit
    < 86400){
  10. $ R = floor ($ limit/3600). 'hour ago ';
  11. } Elseif ($ limit>= 86400 & $ limit
    < 2592000){
  12. $ R = floor ($ limit/86400). 'day before ';
  13. } Elseif ($ limit>= 2592000 & $ limit
    < 31104000){
  14. $ R = floor ($ limit/2592000). 'months ago ';
  15. } Else {
  16. $ R = "long ago ";
  17. }
  18. Return $ r. "(". $ dateStr .")";
  19. }
  20. Echo "Published on:". format_date
    ");
  21. ?>

The above code shows the specific implementation methods for PHP to display the article release time.


Example code for displaying the release time of an article in PHP :? Php functionformat_date ($ dateStr) {$ limit = time ()-strtotime ($ dateStr); $ r =; if ($ limit 60) {$ r = 'gang ';} e...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.