我读过几篇关于set locale的堆栈溢出。我在终端中测试了locale -a,以查看我的语言环境是否在其中,并且确实在其中。在appServiceProvider中添加以下代码规则:
public function boot()
{
Carbon::setLocale($this->app->getLocale());
}$this->app->getLocale()返回"nl“
例如,有人知道为什么Carbon仍然显示周日,而不是Zondag吗?
发布于 2018-08-02 17:08:31
您可能希望在应用程序开始时的某个位置使用setLocale(LC_TIME, $this->app->getLocale())。
然后,如果希望使用带有本地名称的本地化日期格式,请使用formatLocalized函数
Carbon::now()->formatLocalized('%d %B %Y');有关格式化的参数,请参阅http://php.net/manual/en/function.strftime.php
发布于 2019-11-07 15:28:48
使用全球本地化格式转换碳日期的
测试环境: Laravel 5.8、Laravel 6、Laravel 8
在config/app.php
'locale' => 'id', // The default is 'en', but this time I want localize them to Indonesian (ID)然后,要使locale输出如下所示:
// WITHOUT LOCALE
Carbon\Carbon::parse('2019-03-01')->format('d F Y'); //Output: "01 March 2019"
now()->subMinute(5)->diffForHumans(); // Output: "5 minutes ago"
// WITH LOCALE
Carbon\Carbon::parse('2019-03-01')->translatedFormat('d F Y'); // Output: "01 Maret 2019"
now()->subMinute(5)->diffForHumans(); // Output: "5 menit yang lalu"有关转换本地化日期的更多信息,请访问下面的链接https://carbon.nesbot.com/docs/#api-localization
发布于 2018-12-27 22:24:53
试试这个: setLocale(LC_TIME,app()->getLocale());
https://stackoverflow.com/questions/51649569
复制相似问题