fecha_desde->format("l j F -6ren">
gpt4 book ai didi

php - Carbon formatLocalized 在 Blade 中不起作用

转载 作者:可可西里 更新时间:2023-11-01 00:40:32 24 4
gpt4 key购买 nike

在 Blade View 中我有这段代码

{{ \Carbon\Carbon::setLocale("es") }}
{{ $registro->fecha_desde->format("l j F Y") }}<br />
{{ $registro->fecha_desde->formatLocalized("%A %d %B %Y") }}<br />
{{ $registro->fecha_desde->diffForHumans() }}

这不起作用,它返回:

Friday 30 December 2016
Friday 30 December 2016
dentro de 1 semana

因此,format() 和 formatLocalized 总是以英文格式返回日期。diffForHumans 返回本地化日期(在本例中为西类牙语)。

我错过了什么吗?无法相信“Carbon 的 formatLocalized”没有返回本地化的格式化日期....

最佳答案

我找到了两种用其他语言输出日期的方法。在 AppServiceProvider 中添加这个

    Carbon::setLocale('es');
setlocale(LC_TIME,'es_ES');

//This output dates in spanish

在 App.php 中用“es”代替“en”。现在您可以使用 FormatLocalized,所有 Carbon 函数都将使用您在 setLocale 中指定的语言。

注意:如果您使用的是 Oracle 数据库,请添加:

 setlocale(LC_TIME, config('app.locale'));

改为:

setlocale(LC_TIME,'es_ES');

关于php - Carbon formatLocalized 在 Blade 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41252687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com