带mktime的PHP月份区域设置


PHP Month Locale with mktime

因此,我尝试这样做:

setlocale(LC_TIME,"es_ES");
$MonthName = date('F', mktime(0, 0, 0, $month, 10));

但是MonthName仍然是英文的。

我也试过这个:

setlocale(LC_TIME,"es_ES");
$monthObject   = DateTime::createFromFormat('!m', $month);
$MonthName = $monthObject-> format('F'); 

Locale也不起作用。显示名称为英文。

您需要使用strftime(),因为date()DateTime::format不支持区域设置:

setlocale(LC_TIME,"es_ES");    
$month = 11;
$MonthName = strftime('%B', mktime(0, 0, 0, $month, 10));
echo $MonthName; //noviembre