在刀片视图中我有这个代码
{{ \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 DB,请添加:
setlocale(LC_TIME, config('app.locale'));
instead:
setlocale(LC_TIME,'es_ES');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)