문제

Thas my little function:

setlocale(LC_TIME, 'de_DE');
$date_array = array($blog_month,$blog_year);
var_dump($date_array); 
$title_date = strftime("%B %Y", mktime(0,0,0, $date_array[0], 0, $date_array[1]));
echo $title_date;

the var_dump gives

array(2) {
  [0]=> int(5)
  [1]=> int(2013)
}

So the array is correct. But the $title_date is always wrong. In this particular case the echo shows April 2013. I guess something is wrong with the mktime, because i checked the timestamp it gives and it is always the wrong one.

I did read the PHP documentation, and this should be work, don't know whats wrong. Any idea or suggestion?

best regards denym

도움이 되었습니까?

해결책

The setlocale function returns false if the locale couldn't be set, and you are ignoring the return value. In this case the call must be failing (possibly because the de_DE locale isn't installed?) and strftime still formats dates in English.

On the other hand, the day 0 corresponds to the "last day of the month before". So mktime is returning April 30, not May 1 if that's what you expect. For May 1 use this:

mktime(0,0,0, $date_array[0], 1, $date_array[1])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top