4

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)
Prakash Pazhanisamy
  • 997
  • 1
  • 15
  • 25
Amin Jafari
  • 389
  • 4
  • 13

4 Answers4

6

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

Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
Honarkhah
  • 553
  • 7
  • 19
3
$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

Alireza Amrollahi
  • 930
  • 3
  • 12
  • 27
  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/17720679) – Emilio Gort Oct 24 '17 at 13:38
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/17720679) – Doktor OSwaldo Oct 24 '17 at 13:48
1
$formatter->setPattern('yyyy MMMM dd');

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

Prakash Pazhanisamy
  • 997
  • 1
  • 15
  • 25
0

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

SNG
  • 358
  • 4
  • 15