简体   繁体   English

PHP 8.1 中的 strftime

[英]strftime in PHP 8.1

I'm slowly moving all my sites from PHP 7.4 to PHP 8.1 and one of the issues I'm facing is this piece of code:我正在慢慢地将我所有的网站从 PHP 7.4 移动到 PHP 8.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)));

I found the following, but how get it to show only the month?我找到了以下内容,但如何让它只显示月份?

$formatter = new IntlDateFormatter('nl_NL', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
echo $formatter->format(time());

The IntlDateFormatter can accept a special format for the output as a $pattern parameter. IntlDateFormatter 可以接受 output 的特殊格式作为 $pattern 参数。

$dateTime = new DateTime('2022-05-17');

echo \IntlDateFormatter::create('nl_NL', IntlDateFormatter::NONE, IntlDateFormatter::NONE, null, null, 'MMMM')
      ->format($dateTime);  //mei

Try self: https://3v4l.org/IaPnM自己试试: https://3v4l.org/IaPnM

The short form of the month has the format 'MMM'.月份的缩写格式为“MMM”。 In addition to an integer timestamp, the format method also accepts other objects such as DateTime.除了 integer 时间戳之外,格式方法还接受其他对象,例如 DateTime。

For simple cases, the formatLanguage function can also be used, which accepts the well-known Date/DateTime formats.对于简单的情况,也可以使用formatLanguage function ,它接受众所周知的 Date/DateTime 格式。

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

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