date()不尊重当前区域设置,而strftime()则尊重


date() does not respect the current locale, while strftime() does

这是我的测试文件的全部内容:

<?php
setlocale(LC_ALL, 'de_DE');
echo date('F'); // => "February" (wrong)
echo strftime('%B'); // => "Februar" (correct)
?>

你知道为什么会发生这种事吗?我已经在shell中使用locale -a验证了de_DE语言环境是否已安装。

来自手册:

要用其他语言格式化日期,应该使用setlocale()和strftime()函数,而不是date()。

所以你看到的是预期的行为。使用strftime()表示区域设置格式的日期,如果不需要,则使用date()