【问题标题】:laravel carbon formatLocalized() generate three letter month date formatlaravel carbon formatLocalized() 生成三个字母月份日期格式
【发布时间】:2017-10-31 11:42:59
【问题描述】:

我正在使用 carbon 和 laravel 5.5,并希望将日期格式化为仅以三个字母格式显示月份

(ie: 
    January => Jan, 
    February => Feb, 
 ...)

我使用了“M”格式,但它不起作用。这是我的代码:

Carbon\Carbon::parse("2018-03-20")->formatLocalized('%M').

返回

“00”。

有什么想法吗?

【问题讨论】:

  • 现在我要这样做: substr(Carbon\Carbon::parse("2018-03-20")->formatLocalized("%B"), 0, 3) 但是如果有人找到更合适的方法
  • 检查我的答案

标签: php laravel php-carbon


【解决方案1】:

Carbon 的 formatLocalized('%d %B %Y') 为 3 个字母的月份名称返回整个月份字符串,这样使用它:

echo Carbon::parse("2018-03-20")->formatLocalized('%d %b %Y');

输出 2018 年 3 月 20 日

阅读更多关于Localization

【讨论】:

    猜你喜欢
    • 2016-12-01
    • 2018-01-13
    • 1970-01-01
    • 2015-12-12
    • 2018-04-20
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    相关资源
    最近更新 更多