该setlocale()
功能未设置所需的语言(德语)。
目标是输出月份名称。
这是我到目前为止的测试代码:
<?php
date_default_timezone_set('Europe/Berlin');
setlocale(LC_ALL, 'de_DE.utf8');
// Or
setlocale(LC_ALL, 'de_DE@euro');
// Or
setlocale(LC_ALL, 'de_DE');
// Or
setlocale(LC_ALL, 'de');
// Or
setlocale(LC_ALL, 'ge');
echo strftime('%B');
输出:
六月
代替
朱尼
有什么建议么?
PHP 5.6版
如果您没有外壳访问服务器,则此解决方案可能会有所帮助。
如果您具有外壳访问权限,那么本杰明·塞勒(BenjaminSeiller)的答案是最好的!
由于我没有其他可能性(外壳),因此我使用IntlDateFormatter类找到了仅使用PHP的解决方案。
<?php
// Example vars
$month = '6';
$year = '2014';
$fmt = new IntlDateFormatter('de_DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Berlin',
IntlDateFormatter::GREGORIAN);
$lastMonth = mktime(0, 0, 0, $month -1, 1, $year);
$showLastMonth = $fmt->format($lastMonth);
echo $showLastMonth;