IntlDateFormatter::getCalendar

datefmt_get_calendar

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

IntlDateFormatter::getCalendar -- datefmt_get_calendarLit le calendrier utilisé par l'objet IntlDateFormatter

Description

Style orienté objet

public function IntlDateFormatter::getCalendar(): int|false

Style procédural

function datefmt_get_calendar(IntlDateFormatter $formatter): int|false

Liste de paramètres

formatter

La ressource de formateur IntlDateFormatter.

Valeurs de retour

Le type de calendrier utilisé par le formateur. Peut être soit la constante IntlDateFormatter::TRADITIONAL, soit la constante IntlDateFormatter::GREGORIAN. Retourne false en cas d'échec.

Exemples

Exemple #1 Exemple avec datefmt_get_calendar()

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'Le calendrier du formateur est : ' . datefmt_get_calendar($fmt);
datefmt_set_calendar($fmt, IntlDateFormatter::TRADITIONAL);
echo 'Le calendrier est maintenant : ' . datefmt_get_calendar($fmt);
?>

Exemple #2 Exemple orienté objet

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'Le calendrier du formateur est : ' . $fmt->getCalendar();
$fmt->setCalendar(IntlDateFormatter::TRADITIONAL);
echo 'Le calendrier est maintenant : ' . $fmt->getCalendar();

?>

Exemple #3 Exemple de gestion de locale invalide

<?php
try {
    $fmt = new IntlDateFormatter(
        'locale_invalide',
        IntlDateFormatter::FULL,
        IntlDateFormatter::FULL,
        'je_ne_sais_pas',
        IntlDateFormatter::GREGORIAN,
    );
} catch (\Error $e) {
    // ...
}
?>

L'exemple ci-dessus va afficher :

Le calendrier du formateur est : 1
Le calendrier est maintenant : 0

Voir aussi

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top