如何从碳日期获取德国日名称?
How to get German day name from Carbon date?
我的服务器安装了德国本地,我用locale -a
检查过
这是我试过的:
setlocale(LC_ALL, 'de_DE') or die('Locale not installed');
dd($user->created_at->format('l'));
显示"Monday"。但是,这一天的德语单词应该是 "Montag".
我也试过了
setlocale(LC_ALL, 'de_DE') or die('Locale not installed');
\Carbon\Carbon::setLocale('de_DE');
dd($user->created_at->format('l'));
但它仍然是 "Monday" 而不是 "Montag"。
我错过了什么?
如果您使用的是 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
我的服务器安装了德国本地,我用locale -a
这是我试过的:
setlocale(LC_ALL, 'de_DE') or die('Locale not installed');
dd($user->created_at->format('l'));
显示"Monday"。但是,这一天的德语单词应该是 "Montag".
我也试过了
setlocale(LC_ALL, 'de_DE') or die('Locale not installed');
\Carbon\Carbon::setLocale('de_DE');
dd($user->created_at->format('l'));
但它仍然是 "Monday" 而不是 "Montag"。
我错过了什么?
如果您使用的是 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