How to show month name using PHP_intl?

I keep getting the number instead of the name of the month. I need to get the name of the month, for example July .

$formatter = new \IntlDateFormatter(
    "fa_IR@calendar=persian",
    \IntlDateFormatter::FULL,
    \IntlDateFormatter::FULL,
    'Asia/Tehran',
    \IntlDateFormatter::TRADITIONAL
);
$time = new \DateTime();
$formatter->setPattern('yyyy mm dd');
$formatter->format($time)
+4
source share
4 answers

You can use MMMM.
All available templates are included. This link

$formatter = new \IntlDateFormatter(
    "fa_IR@calendar=persian",
    \IntlDateFormatter::FULL,
    \IntlDateFormatter::FULL,
    'Asia/Tehran',
    \IntlDateFormatter::TRADITIONAL
);
$time = new \DateTime();
$formatter->setPattern('yyyy MMMM dd');
$formatter->format($time)
+4
source
$time = new \DateTime();
$formatter->setPattern('yyyy MMMM dd');
$formatter->format($time)

use MMMM to display the name of the month. for more information: http://userguide.icu-project.org/formatparse/datetime

+3
source
$formatter->setPattern('yyyy MMMM dd');

: http://userguide.icu-project.org/formatparse/datetime

+1

:

setlocale(LC_ALL, 'no_NB.utf-8', 'nor'); // For other stuff
Locale::setDefault('no_NB.utf-8'); // For IntlDateFormatter

$f = new IntlDateFormatter(null, null, null, null, null, 'd. MMMM y');
echo "Date-". $f->format(new DateTime("2017-10-24"))."<br/>";

$f = new IntlDateFormatter(null, null, null, null, null, 'MMMM');
echo "Month-". $f->format(new DateTime("2017-10-24"));

:

- 24 2017

-

0

Source: https://habr.com/ru/post/1688080/


All Articles