PHP 8.5.0 RC 2 available for testing

The IntlGregorianCalendar class

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

Introduction

Class synopsis

class IntlGregorianCalendar extends IntlCalendar {
/* Inherited constants */
/* Methods */
public __construct (IntlTimeZone $tz = ?, string $locale = ?)
public __construct (int $timeZoneOrYear, int $localeOrMonth, int $dayOfMonth)
public __construct (
int $timeZoneOrYear,
int $localeOrMonth,
int $dayOfMonth,
int $hour,
int $minute,
int $second = ?
)
public static createFromDate (int $year, int $month, int $dayOfMonth): static
public static createFromDateTime (
int $year,
int $month,
int $dayOfMonth,
int $hour,
int $minute,
? int $second = null
): static
public isLeapYear (int $year): bool
public setGregorianChange (float $timestamp): bool
/* Inherited methods */
public IntlCalendar::add (int $field, int $value): bool
public IntlCalendar::clear (? int $field = null ): true
public IntlCalendar::fieldDifference (float $timestamp, int $field): int |false
public static IntlCalendar::fromDateTime (DateTime |string $datetime, ? string $locale = null ): ? IntlCalendar
public IntlCalendar::get (int $field): int |false
public static IntlCalendar::getKeywordValuesForLocale (string $keyword, string $locale, bool $onlyCommon): IntlIterator |false
public static IntlCalendar::getNow (): float
public IntlCalendar::isSet (int $field): bool
public IntlCalendar::isWeekend (? float $timestamp = null ): bool
public IntlCalendar::roll (int $field, int |bool $value): bool
public IntlCalendar::set (int $field, int $value): true
public IntlCalendar::set (
int $year,
int $month,
int $dayOfMonth = NULL,
int $hour = NULL,
int $minute = NULL,
int $second = NULL
): true
public IntlCalendar::setDate (int $year, int $month, int $dayOfMonth): void
public IntlCalendar::setDateTime (
int $year,
int $month,
int $dayOfMonth,
int $hour,
int $minute,
? int $second = null
): void
public IntlCalendar::setLenient (bool $lenient): true
public IntlCalendar::setTime (float $timestamp): bool
}

Table of Contents

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes 1 note

up
0
Julian Sawicki
4 years ago
I was using `IntlGregorianCalendar` because it offered a nice way to get the week number of the year as an integer. This differs from `DateTime`; `DateTime` gives you the week number of the year as an string.

<?php

$dateTime
= new DateTime('21-09-2020 09:00:00');
echo
$dateTime->format("W"); // string '39'

$intlCalendar = IntlCalendar::fromDateTime ('21-09-2020 09:00:00');
echo
$intlCalendar->get(IntlCalendar::FIELD_WEEK_OF_YEAR); // integer 39
+add a note

AltStyle によって変換されたページ (->オリジナル) /