我想将我看到的日期的语言从英语更改为法语
{{ strftime("%d %B %Y, %H:%M", strtotime($article->created_at)) }}
我们可以使用另一种方法与translatedFormat
Carbon::setLocale('fr');
echo $base_weight_category->created_at->translatedFormat('l jS F Y');
我们可以看到 jeudi 2 avril 2020 的结果
先设置
Carbon
语言环境,然后访问
Carbon::setLocale('fr');
$date_to_show_in_view = $article->created_at->diffForHumans();
对于您的第二个查询(以获得
15 Mars 2018
),请使用此-
<?php
setlocale(LC_TIME, 'French');
echo $base_weight_category->created_at->formatLocalized('%d %B %Y');
?>
我总是在模型中使用此函数的属性
public function getReservationDateFormatAttribute() {
return Carbon::parse($this->reservation_date)->locale(app()->getLocale())->translatedFormat('d F Y');
}
在 get 和 Attribute 之间,我传递了我将在示例中调用的属性的名称或标题,将以这种方式调用它
$model_name->reservation_date_format;
问题的更具体答案是下一个代码
Carbon::parse($this->reservation_date)->locale(app()->getLocale())->translatedFormat('d F Y');
在我们解析您传递的值之后,只需将区域设置设置为您想要的任何内容,在我的示例中,我使用应用程序区域设置,因为该项目是多语言的 在区域设置之后,使用您喜欢的应用程序的 fromat。 希望答案有帮助