Reputation: 429
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
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
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
Reputation: 983
$formatter->setPattern('yyyy MMMM dd');
For more: http://userguide.icu-project.org/formatparse/datetime
Upvotes: 1
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