如何从碳日期获得德国日名称?

问题描述 投票:1回答:1

德语本地安装在我的服务器上,我检查了locale -a

enter image description here

这是我试过的:

setlocale(LC_ALL, 'de_DE') or die('Locale not installed');
dd($user->created_at->format('l'));

它显示“星期一”。但是,今天的德语单词应该是“Montag”。

我也试过了

setlocale(LC_ALL, 'de_DE') or die('Locale not installed');
\Carbon\Carbon::setLocale('de_DE'); 
dd($user->created_at->format('l'));

但它仍然是“星期一”而不是“蒙塔格”。

我错过了什么?

php laravel locale php-carbon
1个回答
1
投票

如果您使用的是Carbon 1,请使用以下内容

$newLocale = setlocale(LC_TIME, 'German');
$dt = Carbon::parse('1975-05-21 22:23:00.123456');
if ($newLocale === false) {
    echo '"German" locale is not installed on your machine, it may have a different name on your machine or you may need to install it.';
}
echo $dt->formatLocalized('%A %d %B %Y');          // Mittwoch 21 Mai 1975
setlocale(LC_TIME, 'English');
echo $dt->formatLocalized('%A %d %B %Y');          // Wednesday 21 May 1975
setlocale(LC_TIME, ''); // reset locale

doc link

© www.soinside.com 2019 - 2024. All rights reserved.