Amin Jafari
Amin Jafari

Reputation: 429

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)

Upvotes: 4

Views: 1804

Answers (4)

Honarkhah
Honarkhah

Reputation: 553

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

Upvotes: 6

Alireza Amrollahi
Alireza Amrollahi

Reputation: 915

$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

Upvotes: 3

Prakash Pazhanisamy
Prakash Pazhanisamy

Reputation: 983

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

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

Upvotes: 1

SNG
SNG

Reputation: 357

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

Upvotes: 0

Related Questions