The IntlGregorianCalendar class

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

简介

类摘要

IntlGregorianCalendar extends IntlCalendar {
/* 继承的常量 */
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 ;
/* 方法 */
public __construct ( IntlTimeZone $tz = ? , string $locale = ? )
public getGregorianChange ( ) : float|false
public isLeapYear ( int $year ) : bool
public setGregorianChange ( float $date ) : bool
/* 继承的方法 */
public IntlCalendar::add ( int $field , int $value ) : bool
public IntlCalendar::after ( IntlCalendar $other ) : bool
public IntlCalendar::before ( IntlCalendar $other ) : bool
public IntlCalendar::clear ( int|null $field = null ) : bool
public static IntlCalendar::createInstance ( IntlTimeZone|DateTimeZone|string|null $timezone = null , string|null $locale = null ) : IntlCalendar|null
public IntlCalendar::equals ( IntlCalendar $other ) : bool
public IntlCalendar::fieldDifference ( float $timestamp , int $field ) : int|false
public static IntlCalendar::fromDateTime ( DateTime|string $datetime , string|null $locale = null ) : IntlCalendar|null
public IntlCalendar::get ( int $field ) : int|false
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|false
public IntlCalendar::getErrorMessage ( ) : string|false
public IntlCalendar::getFirstDayOfWeek ( ) : int|false
public IntlCalendar::getGreatestMinimum ( int $field ) : int|false
public static IntlCalendar::getKeywordValuesForLocale ( string $keyword , string $locale , bool $onlyCommon ) : IntlIterator|false
public IntlCalendar::getLeastMaximum ( int $field ) : int|false
public IntlCalendar::getLocale ( int $type ) : 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|false
public IntlCalendar::getType ( ) : string
public IntlCalendar::getWeekendTransition ( int $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|null $timestamp = null ) : bool
public IntlCalendar::roll ( int $field , int|bool $value ) : 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 $lenient ) : bool
public IntlCalendar::setMinimalDaysInFirstWeek ( int $days ) : bool
public IntlCalendar::setRepeatedWallTimeOption ( int $option ) : bool
public IntlCalendar::setSkippedWallTimeOption ( int $option ) : bool
public IntlCalendar::setTime ( float $timestamp ) : bool
public IntlCalendar::setTimeZone ( IntlTimeZone|DateTimeZone|string|null $timezone ) : bool
}

Table of Contents

User Contributed Notes

Julian Sawicki 22-Oct-2020 12:29
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
PHP8中文手册 站长在线 整理 版权归PHP文档组所有