我正在使用setlocale(LC_TIME, "de_DE");
来设置本地时间,我的html中有<?php echo strftime("%x"); ?>
。
setlocale(LC_TIME, "de_DE");
<?php echo strftime("%x"); ?>
在 PHP 手册中%x
它说Preferred date representation based on locale, without the time
Example: 02/05/09 for February 5, 2009
但使用该示例它将更改为 05/02/09。
如何保持格式February 5, 2009
,如果是一天排在第一位的国家/地区,请显示5 February 2009
而不是将其切换为02/05/09
实现此目的的一种方法是创建一个区域设置值数组,其中月份在打印输出中排在第一位,然后在打印前检查您的区域设置值是否在该数组中。
例:
$month_first_locales = array("de_DE", "fr_CA"); //add locales where date is formatted like 5 February 2009
$locale = "de_DE";
setlocale(LC_TIME, $locale);
if(in_array($locale, $month_first_locales)){
echo strftime("%d %B %Y");
}else{
echo strftime("%B %d, %Y");
}