升级到 PHP 8.1 时,我收到有关“strftime”的错误。如何更正代码以正确显示任何语言的完整月份名称?
$date = strftime("%e %B %Y", strtotime('2010-01-08'))
Run Code Online (Sandbox Code Playgroud)
SNS*_*que 13
对于我亲爱的迟来的 strftime()...我找到了一种适应 IntlDateFormatter::formatObject 的方法,这里是模式引用的链接:
\nhttps://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table
\n...对于那些想要更精确地设置日期格式的人
\n// "date_default_timezone_set" may be required by your server\ndate_default_timezone_set( \'Europe/Paris\' );\n\n// make a DateTime object \n// the "now" parameter is for get the current date, \n// but that work with a date recived from a database \n// ex. replace "now" by \'2022-04-04 05:05:05\'\n$dateTimeObj = new DateTime(\'now\', new DateTimeZone(\'Europe/Paris\'));\n\n// format the date according to your preferences\n// the 3 params are [ DateTime object, ICU date scheme, string locale ]\n$dateFormatted = \nIntlDateFormatter::formatObject( \n $dateTimeObj, \n \'eee d MMMM y \xc3\xa0 HH:mm\', \n \'fr\' \n);\n\n// test :\necho ucwords($dateFormatted);\n\n// output : Jeu. 7 Avril 2022 \xc3\xa0 04:56\nRun Code Online (Sandbox Code Playgroud)\n
我选择使用php81_bc/strftime作曲家包作为替代品。
这里是文档。
请注意,输出可能与本机不同,strftime因为php81_bc/strftime使用不同的库进行区域设置感知格式 (ICU)。
请注意,libc sprintf 和此函数之间的输出可能略有不同,因为它使用 ICU。
小智 -3
嘿,我也遇到过这个问题,所以在对 PHP 官方文档进行一些研究后,我发现了这一点!
https://www.php.net/manual/en/function.strftime.php
他们说它已被废弃,并且使用setlocale()功能也与 相同strftime()。
欲了解更多信息,请访问官方 PHP 文档setlocale() https://www.php.net/manual/en/function.setlocale.php
| 归档时间: |
|
| 查看次数: |
42334 次 |
| 最近记录: |