我正在慢慢地将我的所有站点从PHP7.4移到PHP8.1,我面临的问题之一是这段代码:
setlocale(LC_TIME, array('nl_NL.UTF-8', 'nl_NL@euro', 'nl_NL', 'dutch'));
echo ucfirst(strftime('%B', mktime(0, 0, 0, 1, 1, 2022)));我发现了以下内容,但如何才能只显示这个月呢?
$formatter = new IntlDateFormatter('nl_NL', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
echo $formatter->format(time());发布于 2022-11-18 19:14:06
IntlDateFormatter可以接受输出的特殊格式作为$pattern参数。
$dateTime = new DateTime('2022-05-17');
echo \IntlDateFormatter::create('nl_NL', IntlDateFormatter::NONE, IntlDateFormatter::NONE, null, null, 'MMMM')
->format($dateTime); //mei这个月的短形式有'MMM‘格式。除了整数时间戳之外,format方法还接受其他对象,如DateTime。
对于简单的情况,也可以使用formatLanguage函数,它接受众所周知的日期/日期时间格式。
https://stackoverflow.com/questions/74492423
复制相似问题