簡體   English   中英

如何使用 PHP_intl 顯示月份名稱?

[英]How to show month name using PHP_intl?

我不斷得到數字而不是月份名稱。 我需要得到像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)

您可以使用 MMMM。
所有可用的模式都在這個鏈接上

$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)

這個問題和這個一樣

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

使用 MMMM 顯示月份名稱。 更多信息: http : //userguide.icu-project.org/formatparse/datetime

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

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

試試這個:

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

輸出:

日期 - 2017 年 10 月 24 日

月份 - 十月

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM