PHP 8.4.0 RC4 available for testing

IntlDatePatternGenerator::getBestPattern

(PHP 8 >= 8.1.0)

IntlDatePatternGenerator::getBestPatternDetermines the most suitable date/time format

Beschreibung

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

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

Parameter-Liste

skeleton

The skeleton.

Rückgabewerte

Returns a format, accepted by DateTimeInterface::format() on success, Bei einem Fehler wird false zurückgegeben..

Beispiele

Beispiel #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');
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

de: 24.04.2021
en: 04/24/2021

add a note

User Contributed Notes 1 note

up
2
ICU User
2 years ago
Use pattern letter "j" in skeleton to get a localized time string: https://unicode-org.github.io/icu/userguide/format_parse/datetime/index#datetimepatterngenerator

"j" gets mapped to one of "H", "h", "k" or "K".
To Top