Hw用laravel将月份格式化为3个字母



我想用这种格式显示日期:

1st Jan, 2021

月份应该显示在3个字母而不是全名中,目前我得到的格式是:

01 January, 2021

我使用以下代码:

{{date('d F, Y', strtotime($bootcamp->event_start))}} 
{{date('jS M, Y', strtotime($bootcamp->event_start))}} 

使用简单日期函数https://www.w3schools.com/php/func_date_date.asp

最简单的方法是使用Carbon格式化日期。要获得您需要的格式,您可以执行以下操作:

>>> CarbonCarbon::parse($bootcamp->event_start)->format('dd M, Y');
=> "1st Jan, 2021"

或者,您仍然可以使用date((函数,但将其更改为:

date('dd M, Y', strtotime($bootcamp->event_start));
=> "1st Jan, 2021"

您描述的格式似乎是:

jS M, Y

正如我们在文档中看到的:

jS: "7th", "22nd", "31"
M: 'jan' | 'feb' | 'mar' |
Y: "1991", "1992", "1993"

那就是:

{{date('jS M, Y', strtotime($bootcamp->event_start))}}

最新更新