Localized (short) month names using IntlDateFormatter in PHP?

后端 未结 2 1179
执笔经年
执笔经年 2021-01-02 03:07

On my Windows development machine, I have set the locale to ita:

setlocale(LC_TIME, \'ita\');
echo strft         


        
2条回答
  •  情话喂你
    2021-01-02 03:56

    Quite ugly, but it works:

    $formatter = \IntlDateFormatter::create(
        'it',
        \IntlDateFormatter::LONG,
        \IntlDateFormatter::NONE,
        \DateTimeZone::UTC, // Doesn't matter
        \IntlDateFormatter::GREGORIAN,
        'MMM'
    );
    
    $months = array_map(
        function($m) use($formatter){
            return $formatter->format(mktime(0, 0, 0, $m, 2, 1970));
        },
        range(1, 12)
    );
    
    var_dump($months);
    

    Strange thing is with it month names are lower case, with en they have the right case. I'll leave the question unanswered looking for a better solution!

提交回复
热议问题