【问题标题】:Presenting current date in full text format以全文格式显示当前日期
【发布时间】:2017-03-18 20:33:50
【问题描述】:

我正在使用jenssegers/date 和carbon 来显示当前日期和时间。

我可以使用此代码以文本方式显示完整日期:

echo Date::now()->format('l j F Y H:i:s'); // example from jenssegers docs

现在,在 Codrops demo 中,日期显示为

<div class="slide__element slide__element--date">Saturday, 25<sup>th</sup> of October 2043</div>

我的问题

如何构建一个帮助器以这种方式准确显示当前日期,包括用sup 元素包装th(或nd、st)?

【问题讨论】:

    标签: laravel date laravel-5.3 php-carbon presenter


    【解决方案1】:
    >>> \Carbon\Carbon::now()->format("l j <\s\up>S</\s\up> F Y H:i:s")
    => "Friday 4 <sup>th</sup> November 2016 22:11:16"
    

    注意 s 和 u 被转义了。

    format() 采用日期格式字符串,您可以在该字符串中添加任何您想要的字符,如果它们与 PHP 格式字符串字符匹配,您只需将它们转义即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      相关资源
      最近更新 更多