简体   繁体   English

如何使用 PHP_intl 显示月份名称?

[英]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 .我需要得到像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.您可以使用 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.使用 MMMM 显示月份名称。 for more info : http://userguide.icu-project.org/formatparse/datetime更多信息: 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日期 - 2017 年 10 月 24 日

Month - oktober月份 - 十月

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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