php intldateFormatter-删除“天”从日期格式开始
我想从图案中删除“天”,以显示正确的INTL日期,格式为“ F,y”。 如何在$ temppattern变量中使用点(和其他符号)的str_replace-ing“ d”字符正确地正确执行?
我不能使用$ formatter-> setPattern(),因为每种语言的日期格式都不同。
function getLocaleDateFormate($locale) {
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::LONG, IntlDateFormatter::NONE);
// replace M with L: stand-alone month in year
$tempPattern = $formatter->getPattern();
$tempPattern = str_replace("M", "L", $tempPattern);
return $tempPattern;
}
echo getLocaleDateFormate("sk"); // d. LLLL y
echo getLocaleDateFormate("hu"); // y. LLLL d.
echo getLocaleDateFormate("de"); // d. LLLL y
echo getLocaleDateFormate("es"); // d 'de' LLLL 'de' y
echo getLocaleDateFormate("pl"); // d LLLL y
echo getLocaleDateFormate("cn"); // y年L月d
I want to remove "day" from the pattern to display the correct INTL date in format "F, Y".
How to correctly do it without str_replace-ing "d" character with dots (and other symbols) in the $tempPattern variable?
I can't use $formatter->setPattern(), as the date format is different for each language.
function getLocaleDateFormate($locale) {
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::LONG, IntlDateFormatter::NONE);
// replace M with L: stand-alone month in year
$tempPattern = $formatter->getPattern();
$tempPattern = str_replace("M", "L", $tempPattern);
return $tempPattern;
}
echo getLocaleDateFormate("sk"); // d. LLLL y
echo getLocaleDateFormate("hu"); // y. LLLL d.
echo getLocaleDateFormate("de"); // d. LLLL y
echo getLocaleDateFormate("es"); // d 'de' LLLL 'de' y
echo getLocaleDateFormate("pl"); // d LLLL y
echo getLocaleDateFormate("cn"); // y年L月d
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
输出不是正确的顺序(它迫使每种语言的“ llll y”顺序),因此我对特定语言进行了更正。我不完全满意,但没有更好的解决方案。
The output is not in the correct order (it forces the 'LLLL y' order for each language), so I applied the corrections for specific languages. I am not satisfied fully but I don't have any better solution.
我最终创建了一个可以在当地格式化日期的函数,希望能提供帮助!
使用 :
I ended up creating a function that would format dates locally, hoping to help !
Use :