phpday 2021 digital edition

The IntlGregorianCalendar class

(PHP 5 >= 5.5.0, PHP 7)

Introduction

Synopsis de la classe

IntlGregorianCalendar extends IntlCalendar {
/* Constants héritées */
const int IntlCalendar::FIELD_ERA = 0 ;
const int IntlCalendar::FIELD_YEAR = 1 ;
const int IntlCalendar::FIELD_MONTH = 2 ;
const int IntlCalendar::FIELD_DATE = 5 ;
const int IntlCalendar::FIELD_AM_PM = 9 ;
const int IntlCalendar::FIELD_HOUR = 10 ;
const int IntlCalendar::FIELD_MINUTE = 12 ;
const int IntlCalendar::FIELD_SECOND = 13 ;
const int IntlCalendar::DOW_SUNDAY = 1 ;
const int IntlCalendar::DOW_MONDAY = 2 ;
const int IntlCalendar::DOW_TUESDAY = 3 ;
const int IntlCalendar::DOW_FRIDAY = 6 ;
/* Méthodes */
public __construct ( IntlTimeZone $tz = ? , string $locale = ? )
public getGregorianChange ( ) : float|false
public isLeapYear ( int $year ) : bool
public setGregorianChange ( float $date ) : bool
/* Méthodes héritées */
public IntlCalendar::add ( int $field , int $amount ) : bool
public IntlCalendar::after ( IntlCalendar $other ) : bool
public IntlCalendar::before ( IntlCalendar $other ) : bool
public IntlCalendar::clear ( int $field = NULL ) : bool
public static IntlCalendar::createInstance ( mixed $timeZone = NULL , string $locale = "" ) : IntlCalendar
public IntlCalendar::equals ( IntlCalendar $other ) : bool
public IntlCalendar::fieldDifference ( float $when , int $field ) : int|false
public static IntlCalendar::fromDateTime ( mixed $dateTime ) : IntlCalendar
public IntlCalendar::get ( int $field ) : int
public IntlCalendar::getActualMaximum ( int $field ) : int|false
public IntlCalendar::getActualMinimum ( int $field ) : int|false
public static IntlCalendar::getAvailableLocales ( ) : array
public IntlCalendar::getDayOfWeekType ( int $dayOfWeek ) : int|false
public IntlCalendar::getErrorCode ( ) : int
public IntlCalendar::getErrorMessage ( ) : string
public IntlCalendar::getFirstDayOfWeek ( ) : int|false
public IntlCalendar::getGreatestMinimum ( int $field ) : int|false
public static IntlCalendar::getKeywordValuesForLocale ( string $key , string $locale , bool $commonlyUsed ) : Iterator|false
public IntlCalendar::getLeastMaximum ( int $field ) : int|false
public IntlCalendar::getLocale ( int $localeType ) : string|false
public IntlCalendar::getMaximum ( int $field ) : int|false
public IntlCalendar::getMinimum ( int $field ) : int|false
public static IntlCalendar::getNow ( ) : float
public IntlCalendar::getTime ( ) : float
public IntlCalendar::getType ( ) : string
public IntlCalendar::getWeekendTransition ( string $dayOfWeek ) : int|false
public IntlCalendar::inDaylightTime ( ) : bool
public IntlCalendar::isEquivalentTo ( IntlCalendar $other ) : bool
public IntlCalendar::isLenient ( ) : bool
public IntlCalendar::isSet ( int $field ) : bool
public IntlCalendar::isWeekend ( float $date = NULL ) : bool
public IntlCalendar::roll ( int $field , mixed $amountOrUpOrDown ) : bool
public IntlCalendar::set ( int $field , int $value ) : bool
public IntlCalendar::set ( int $year , int $month , int $dayOfMonth = NULL , int $hour = NULL , int $minute = NULL , int $second = NULL ) : bool
public IntlCalendar::setFirstDayOfWeek ( int $dayOfWeek ) : bool
public IntlCalendar::setLenient ( bool $isLenient ) : bool
public IntlCalendar::setMinimalDaysInFirstWeek ( int $minimalDays ) : bool
public IntlCalendar::setRepeatedWallTimeOption ( int $wallTimeOption ) : bool
public IntlCalendar::setSkippedWallTimeOption ( int $wallTimeOption ) : bool
public IntlCalendar::setTime ( float $date ) : bool
public IntlCalendar::setTimeZone ( mixed $timeZone ) : bool
}

Sommaire

add a note add a note

User Contributed Notes 1 note

up
1
Julian Sawicki
6 months 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
To Top