PHP Date function output in Italian

后端 未结 6 1194
误落风尘
误落风尘 2020-11-29 08:17

I am trying to output dates in the Italian format using date() as follows:



        
6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 09:17

    I found that setlocale isn't reliable, as it is set per process, not per thread (the manual mentions this). This means other running scripts can change the locale at any time. A solution is using IntlDateFormatter from the intl php extension.

    $fmt = new \IntlDateFormatter('it_IT', NULL, NULL);
    $fmt->setPattern('d MMMM yyyy HH:mm'); 
    // See: http://userguide.icu-project.org/formatparse/datetime for pattern syntax
    echo $fmt->format(new \DateTime()); 
    

    If it doesn't work you might need to:

    • Install intl php extension (ubuntu example): sudo apt-get install php5-intl

    • Install the locale you want to use: sudo locale-gen it_IT

提交回复
热议问题