哈希空间 Ctrl + F 进行搜索
首页 php手册中文版 CSS中文手册 哈希文档 Markdown在线工具

IntlDatePatternGenerator::getBestPattern

(PHP 8 >= 8.1.0)

IntlDatePatternGenerator::getBestPatternDetermines the most suitable date/time format

说明

public IntlDatePatternGenerator::getBestPattern(string $skeleton): string|false

Determines which date/time format is most suitable for a particular locale.

参数

skeleton

The skeleton.

返回值

Returns a format, accepted by DateTimeInterface::format() on success, 或者在失败时返回 false.

范例

示例 #1 IntlDatePatternGenerator::getBestPattern() example

<?php

$skeleton 
'YYYYMMdd';
$today = \DateTimeImmutable::createFromFormat('Y-m-d''2021-04-24');
 
$patternGenerator = new \IntlDatePatternGenerator('de_DE');
$pattern $patternGenerator->getBestPattern($skeleton);
echo 
'de: ', \IntlDateFormatter::formatObject($today$pattern'de_DE'), "\n";
 
$patternGenerator = new \IntlDatePatternGenerator('en_US');
$pattern $patternGenerator->getBestPattern($skeleton);
echo 
'en: ', \IntlDateFormatter::formatObject($today$pattern'en_US');
?>

以上例程会输出:

de: 24.04.2021
en: 04/24/2021
打开 哈希空间 微信小程序中查看更佳