【问题标题】:How to convert time in php to user friendly text?如何将 php 中的时间转换为用户友好的文本?
【发布时间】:2011-12-17 16:47:36
【问题描述】:

我使用以下代码在我的网站上显示博客文章的时间:

strftime('%B %e, %Y',strtotime($row->date))

返回以下字符串:

November 7, 2011

如何调整上述代码以在数字末尾显示 (..st, ..nd, ..rd, ..th)。所以我可以将日期显示为:

 November 7th, 2011

等等

【问题讨论】:

    标签: php string date time


    【解决方案1】:

    使用date() 时,S 字符被替换为 st、nd、rd 或 th:

    date("F jS, Y", strtotime($row->date))
    

    【讨论】:

      【解决方案2】:

      你应该像这样使用date()

      echo date('F jS, Y',strtotime($row->date));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-10
        相关资源
        最近更新 更多