简体   繁体   中英

How to show month name using PHP_intl?

I keep getting number instead of month name. I need to get the month name like 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)

You can use MMMM.
All available pattern is on 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)

This question is same as this

$time = new \DateTime();
$formatter->setPattern('yyyy MMMM dd');
$formatter->format($time)

use MMMM to show month name. for more info : http://userguide.icu-project.org/formatparse/datetime

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

更多信息: http : //userguide.icu-project.org/formatparse/datetime

Try this:

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"));

Output:

Date - 24 oktober 2017

Month - oktober

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM