所以如果我使用:
<?php echo date_format($date, "j M Y") ?>
我得到以下格式的日期:1950 年 1 月 5 日。
但是,我想要的是:1950 年 1 月 5 日
我将如何添加额外的 th?
最佳答案
看这里的格式http://www.php.net/manual/en/function.date.php , 但是
<?php echo date_format($date, "jS M Y") ?><br>
对于国际日期,我猜你会做这样的事情:
$ordinal = new NumberFormatter($locale, NumberFormatter::ORDINAL);
$ordinal = $ordinal->format(date_format($date, "j"));
$pattern = "d'{$ordinal}' MMM yyyy";
$dateFormatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, $timezone, IntlDateFormatter::GREGORIAN);
$dateFormatter->setPattern($pattern);
$dateFormatter->format($date->getTimestamp());
以上内容未经测试,但似乎可行。
关于php - 格式化日期,日期的序号后缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24296390/