# 日期与时间

* [DateTime](#datetime)
  * [DateTime::__construct - 返回一个新的 DateTime 对象](#datetimeconstruct)
  * [DateTime::add - 给一个 DateTime 对象增加一定量的天，月，年，小时，分钟以及秒](#datetimeadd)
  * [DateTime::createFromFormat - 根据给定的格式解析日期时间字符串](#datetimecreatefromformat)
  * [DateTime::createFromImmutable - 返回封装给定 DateTimeImmutable 对象的新 DateTime 对象](#datetimecreatefromimmutable)
  * [DateTime::getLastErrors - 获取警告和错误信息](#datetimegetlasterrors)
  * [DateTime::modify - 修改日期时间对象的值](#datetimemodify)
  * [DateTime::setDate - 设置 DateTime 对象的日期](#datetimesetdate)
  * [DateTime::setISODate - 设置 ISO 日期](#datetimesetisodate)
  * [DateTime::setTime - 设置 DateTime 对象的时间](#datetimesettime)
  * [DateTime::setTimestamp - 以 Unix 时间戳的方式设置 DateTime 对象](#datetimesettimestamp)
  * [DateTime::setTimezone - 设置 DateTime 对象的时区](#datetimesettimezone)
  * [DateTime::sub - 对一个 DateTime 对象减去一定量的日，月，年，小时，分钟以及秒](#datetimesub)
* [DateTimeImmutable](#datetimeimmutable)
  * [DateTimeImmutable::__construct - 返回新的 DateTimeImmutable 对象](#datetimeimmutableconstruct)
  * [DateTimeImmutable::add - 增加一定量的天，月，年，小时，分钟和秒](#datetimeimmutableadd)
  * [DateTimeImmutable::createFromFormat - 根据指定格式解析时间字符串](#datetimeimmutablecreatefromformat)
  * [DateTimeImmutable::createFromMutable - 返回封装给定 DateTime 对象的新 DateTimeImmutable 对象](#datetimeimmutablecreatefrommutable)
  * [DateTimeImmutable::getLastErrors - 返回警告和错误](#datetimeimmutablegetlasterrors)
  * [DateTimeImmutable::modify - 创建一个具有修改后的时间戳的新对象](#datetimeimmutablemodify)
  * [DateTimeImmutable::setDate - 设定日期](#datetimeimmutablesetdate)
  * [DateTimeImmutable::setISODate - 设定 ISO 日期](#datetimeimmutablesetisodate)
  * [DateTimeImmutable::setTime - 设定时间](#datetimeimmutablesettime)
  * [DateTimeImmutable::setTimestamp - 根据 Unix 时间戳设置日期和时间](#datetimeimmutablesettimestamp)
  * [DateTimeImmutable::setTimezone - 设置时区](#datetimeimmutablesettimezone)
  * [DateTimeImmutable::sub - 减去一定量的天，月，年，小时，分钟和秒](#datetimeimmutablesub)
* [DateTimeInterface](#datetimeinterface)
  * [DateTime::diff - 返回两个 DateTime 对象之间的差](#datetimediff)
  * [DateTime::format - 返回根据给定格式格式化的日期](#datetimeformat)
  * [DateTime::getOffset - 返回时区偏移量](#datetimegetoffset)
  * [DateTime::getTimestamp - 获取 Unix 时间戳](#datetimegettimestamp)
  * [DateTime::getTimezone - 返回相对于给定 DateTime 的时区](#datetimegettimezone)
* [DateTimeZone](#datetimezone)
  * [DateTimeZone::__construct - 创建新的 DateTimeZone 对象](#datetimezoneconstruct)
  * [DateTimeZone::getLocation - 返回与时区相关的定位信息](#datetimezonegetlocation)
  * [DateTimeZone::getName - 返回时区名称](#datetimezonegetname)
  * [DateTimeZone::getOffset - 返回相对于 GMT 的时差](#datetimezonegetoffset)
  * [DateTimeZone::getTransitions - 返回时区的所有转换](#datetimezonegettransitions)
  * [DateTimeZone::listAbbreviations - 返回一个包含夏令时，时差和时区信息的关联数组](#datetimezonelistabbreviations)
  * [DateTimeZone::listIdentifiers - 返回一个包含了所有时区标示符的索引数组](#datetimezonelistidentifiers)
* [DateInterval](#dateinterval)
  * [DateInterval::__construct - 创建一个新的 DateInterval 对象](#dateintervalconstruct)
  * [DateInterval::createFromDateString - 从字符串的相对部分设置 DateInterval](#dateintervalcreatefromdatestring)
  * [DateInterval::format - 格式化间隔](#dateintervalformat)
* [DatePeriod](#dateperiod)
  * [DatePeriod::__construct - 创建一个新的 DatePeriod 对象](#dateperiodconstruct)
  * [DatePeriod::getDateInterval - 获取间隔](#dateperiodgetdateinterval)
  * [DatePeriod::getEndDate - 获取结束日期](#dateperiodgetenddate)
  * [DatePeriod::getRecurrences - 获取重复次数](#dateperiodgetrecurrences)
  * [DatePeriod::getStartDate - 获取开始日期](#dateperiodgetstartdate)
* [Date / Time](#date--time)
  * [checkdate - 验证一个格里高里日期](#checkdate)
  * [date_add - 给一个 DateTime 对象增加一定量的天，月，年，小时，分钟以及秒](#dateadd)
  * [date_create_from_format - 根据给定的格式解析日期时间字符串](#datecreatefromformat)
  * [date_create_immutable_from_format - 根据指定格式解析时间字符串](#datecreateimmutablefromformat)
  * [date_create_immutable - 返回新的 DateTimeImmutable 对象](#datecreateimmutable)
  * [date_create - 返回一个新的 DateTime 对象](#datecreate)
  * [date_date_set - 设置 DateTime 对象的日期](#datedateset)
  * [date_default_timezone_get - 取得一个脚本中所有日期时间函数所使用的默认时区](#datedefaulttimezoneget)
  * [date_default_timezone_set - 设定用于一个脚本中所有日期时间函数的默认时区](#datedefaulttimezoneset)
  * [date_diff - 返回两个 DateTime 对象之间的差](#datediff)
  * [date_format - 返回根据给定格式格式化的日期](#dateformat)
  * [date_get_last_errors - 获取警告和错误信息](#dategetlasterrors)
  * [date_interval_create_from_date_string - 从字符串的相对部分设置 DateInterval](#dateintervalcreatefromdatestring)
  * [date_interval_format - 格式化间隔](#dateintervalformat)
  * [date_isodate_set - 设置 ISO 日期](#dateisodateset)
  * [date_modify - 修改日期时间对象的值](#datemodify)
  * [date_offset_get - 返回时区偏移量](#dateoffsetget)
  * [date_parse_from_format - 获取有关根据指定格式格式化的给定日期的信息](#dateparsefromformat)
  * [date_parse - 返回具有给定日期的详细信息的关联数组](#dateparse)
  * [date_sub - 对一个 DateTime 对象减去一定量的日，月，年，小时，分钟以及秒](#datesub)
  * [date_sun_info - 返回一个数组，其中包含有关日落 / 日出和暮光开始 / 结束的信息](#datesuninfo)
  * [date_sunrise - 返回给定的日期与地点的日出时间](#datesunrise)
  * [date_sunset - 返回给定的日期与地点的日落时间](#datesunset)
  * [date_time_set - 设置 DateTime 对象的时间](#datetimeset)
  * [date_timestamp_get - 获取 Unix 时间戳](#datetimestampget)
  * [date_timestamp_set - 以 Unix 时间戳的方式设置 DateTime 对象](#datetimestampset)
  * [date_timezone_get - 返回相对于给定 DateTime 的时区](#datetimezoneget)
  * [date_timezone_set - 设置 DateTime 对象的时区](#datetimezoneset)
  * [date - 格式化一个本地时间 / 日期](#date)
  * [getdate - 取得日期 / 时间信息](#getdate)
  * [gettimeofday - 取得当前时间](#gettimeofday)
  * [gmdate - 格式化一个 GMT / UTC 日期 / 时间](#gmdate)
  * [gmstrftime - 根据区域设置格式化 GMT / UTC 时间 / 日期](#gmstrftime)
  * [idate - 将本地时间日期格式化为整数](#idate)
  * [localtime - 取得本地时间](#localtime)
  * [microtime - 返回当前 Unix 时间戳和微秒数](#microtime)
  * [strftime - 根据区域设置格式化本地时间 / 日期](#strftime)
  * [strtotime - 将任何字符串的日期时间描述解析为 Unix 时间戳](#strtotime)
  * [time - 返回当前的 Unix 时间戳](#time)
  * [timezone_abbreviations_list - 返回一个包含夏令时，时差和时区信息的关联数组](#timezoneabbreviationslist)
  * [timezone_identifiers_list - 返回一个包含了所有时区标示符的索引数组](#timezoneidentifierslist)
  * [timezone_location_get - 返回与时区相关的定位信息](#timezonelocationget)
  * [timezone_name_from_abbr - 返回缩写的时区名称](#timezonenamefromabbr)
  * [timezone_name_get - 返回时区名称](#timezonenameget)
  * [timezone_offset_get - 返回相对于 GMT 的时差](#timezoneoffsetget)
  * [timezone_open - 创建新的 DateTimeZone 对象](#timezoneopen)
  * [timezone_transitions_get - 返回时区的所有转换](#timezonetransitionsget)
  * [timezone_version_get - 获取 timezonedb 的版本](#timezoneversionget)

## DateTime

### DateTime::__construct

```php
<?php

var_dump(new DateTime('2020-01-01'));          // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(new DateTime('2020-01-01 23:59:59')); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(new DateTime('now'));

```

### DateTime::add

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->add(new DateInterval('P10D'))); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-11 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTime::createFromFormat

```php
<?php

var_dump(DateTime::createFromFormat('Y-m-d H:i:s', '2020-01-01 23:59:59')); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTime::createFromImmutable

```php
<?php

var_dump(DateTime::createFromImmutable(new DateTimeImmutable('2020-01-01 23:59:59 UTC'))); // object(DateTime)#2 (3) { ["date"]=> string(26) "2020-01-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTime::getLastErrors

```php
<?php

var_dump(DateTime::getLastErrors()); // bool(false)

```

### DateTime::modify

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->modify('+1 day'));   // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-02 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump($date->modify('-1 day'));   // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump($date->modify('+1 month')); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-02-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTime::setDate

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->setDate(2020, 2, 1)); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-02-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump($date->setDate(2020, 3, 1)); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-03-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTime::setISODate

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->setISODate(2020, 1));    // object(DateTime)#1 (3) { ["date"]=> string(26) "2019-12-30 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump($date->setISODate(2020, 2));    // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-06 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump($date->setISODate(2020, 2, 2)); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-07 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTime::setTime

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->setTime(0, 0, 0)); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump($date->setTime(1, 0, 0)); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 01:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTime::setTimestamp

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->setTimestamp(time()));

```

### DateTime::setTimezone

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->setTimezone(new DateTimezone('PRC'))); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-02 07:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "PRC" }

```

### DateTime::sub

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->sub(new DateInterval('P10D'))); // object(DateTime)#1 (3) { ["date"]=> string(26) "2019-12-22 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

## DateTimeImmutable

### DateTimeImmutable::__construct

```php
<?php

var_dump(new DateTimeImmutable('+1 day'));   // object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2020-05-12 08:42:02.379554" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(new DateTimeImmutable('-1 day'));   // object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2020-05-10 08:42:02.379572" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(new DateTimeImmutable('+1 month')); // object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2020-06-11 08:42:02.379577" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTimeImmutable::add

```php
<?php

$date = new DateTimeImmutable('2020-01-01 23:59:59');
var_dump($date->add(new DateInterval('P10D'))); // object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2020-01-11 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTimeImmutable::createFromFormat

```php
<?php

var_dump(DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2020-01-01 23:59:59')); // object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2020-01-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTimeImmutable::createFromMutable

```php
<?php

var_dump(DateTimeImmutable::createFromMutable(new DateTime('2020-01-01 23:59:59'))); // object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2020-01-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTimeImmutable::getLastErrors

```php
<?php

var_dump(DateTimeImmutable::getLastErrors()); // bool(false)

```

### DateTimeImmutable::modify

```php
<?php

$date = new DateTimeImmutable('2020-01-01 23:59:59');
var_dump($date->modify('+1 day')); // object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2020-01-02 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTimeImmutable::setDate

```php
<?php

$date = new DateTimeImmutable('2020-01-01 23:59:59');
var_dump($date->setDate(2020, 2, 1)); // object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2020-02-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump($date->setDate(2020, 3, 1)); // object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2020-03-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTimeImmutable::setISODate

```php
<?php

$date = new DateTimeImmutable('2020-01-01 23:59:59');
var_dump($date->setISODate(2020, 1)); // object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-30 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump($date->setISODate(2020, 2)); // object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2020-01-06 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTimeImmutable::setTime

```php
<?php

$date = new DateTimeImmutable('2020-01-01 23:59:59');
var_dump($date->setTime(0, 0, 0)); // object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2020-01-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DateTimeImmutable::setTimestamp

```php
<?php

$date = new DateTimeImmutable('2020-01-01 23:59:59');
var_dump($date->setTimestamp(time()));

```

### DateTimeImmutable::setTimezone

```php
<?php

$date = new DateTimeImmutable('2020-01-01 23:59:59');
var_dump($date->setTimezone(new DateTimeZone('UTC'))); // object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2020-01-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump($date->setTimezone(new DateTimeZone('PRC'))); // object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2020-01-02 07:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "PRC" }

```

### DateTimeImmutable::sub

```php
<?php

$date = new DateTimeImmutable('2020-01-01 23:59:59');
var_dump($date->sub(new DateInterval('P10D'))); // object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2019-12-22 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

## DateTimeInterface

### DateTime::diff

```php
<?php

$date1 = new DateTime('2020-01-01 23:59:59');
$date2 = new DateTime('2020-02-01 23:59:59');
var_dump($date1->diff($date2)); // object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(1) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(31) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }

```

### DateTime::format

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->format('Y-m-d'));       // string(10) "2020-01-01"
var_dump($date->format('Y-m-d H:i:s')); // string(19) "2020-01-01 23:59:59"

```

### DateTime::getOffset

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->getOffset());

$date = new DateTime('2020-01-01 23:59:59', new DateTimeZone('America/New_York'));
var_dump($date->getOffset());

```

### DateTime::getTimestamp

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->getTimestamp()); // int(1577923199)

```

### DateTime::getTimezone

```php
<?php

$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->getTimezone()); // object(DateTimeZone)#2 (2) { ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

## DateTimeZone

### DateTimeZone::__construct

```php
<?php

var_dump(new DateTimeZone('UTC')); // object(DateTimeZone)#1 (2) { ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(new DateTimeZone('PRC')); // object(DateTimeZone)#1 (2) { ["timezone_type"]=> int(3) ["timezone"]=> string(3) "PRC" }

```

### DateTimeZone::getLocation

```php
<?php

$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->getLocation()); // array(4) { ["country_code"]=> string(2) "GB" ["latitude"]=> float(51.50833) ["longitude"]=> float(-0.12528) ["comments"]=> string(0) "" }

```

### DateTimeZone::getName

```php
<?php

$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->getName()); // string(13) "Europe/London"

```

### DateTimeZone::getOffset

```php
<?php

$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->getOffset(new DateTime('now')));

```

### DateTimeZone::getTransitions

```php
<?php

$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->getTransitions());

```

### DateTimeZone::listAbbreviations

```php
<?php

$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->listAbbreviations());

```

### DateTimeZone::listIdentifiers

```php
<?php

$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->listIdentifiers());

```

## DateInterval

### DateInterval::__construct

```php
<?php

var_dump(new DateInterval('P10D'));       // object(DateInterval)#1 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(10) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }
var_dump(new DateInterval('P2Y4DT6H8M')); // object(DateInterval)#1 (16) { ["y"]=> int(2) ["m"]=> int(0) ["d"]=> int(4) ["h"]=> int(6) ["i"]=> int(8) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }

```

### DateInterval::createFromDateString

```php
<?php

var_dump(DateInterval::createFromDateString('1 day'));    // object(DateInterval)#1 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(1) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }
var_dump(DateInterval::createFromDateString('2 weeks'));  // object(DateInterval)#1 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(14) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }
var_dump(DateInterval::createFromDateString('3 months')); // object(DateInterval)#1 (16) { ["y"]=> int(0) ["m"]=> int(3) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }
var_dump(DateInterval::createFromDateString('4 years'));  // object(DateInterval)#1 (16) { ["y"]=> int(4) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }

```

### DateInterval::format

```php
<?php

$interval = new DateInterval('P2Y4DT6H8M');
var_dump($interval->format('%y years'));   // string(7) "2 years"
var_dump($interval->format('%d days'));    // string(6) "4 days"
var_dump($interval->format('%h hours'));   // string(7) "6 hours"
var_dump($interval->format('%i minutes')); // string(9) "8 minutes"

```

## DatePeriod

### DatePeriod::__construct

```php
<?php

var_dump(new DatePeriod(new DateTime('2020-01-01'), new DateInterval('P10D'), new DateTime('2020-02-01'))); // object(DatePeriod)#1 (6) { ["start"]=> object(DateTime)#4 (3) { ["date"]=> string(26) "2020-01-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } ["current"]=> NULL ["end"]=> object(DateTime)#3 (3) { ["date"]=> string(26) "2020-02-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } ["interval"]=> object(DateInterval)#2 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(10) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } ["recurrences"]=> int(1) ["include_start_date"]=> bool(true) }

```

### DatePeriod::getDateInterval

```php
<?php

$period = new DatePeriod(new DateTime('2020-01-01'), new DateInterval('P10D'), new DateTime('2020-02-01'));
var_dump($period->getDateInterval()); // object(DateInterval)#4 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(10) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }

```

### DatePeriod::getEndDate

```php
<?php

$period = new DatePeriod(new DateTime('2020-01-01'), new DateInterval('P10D'), new DateTime('2020-02-01'));
var_dump($period->getEndDate()); // object(DateTime)#4 (3) { ["date"]=> string(26) "2020-02-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### DatePeriod::getRecurrences

```php
<?php

$period = new DatePeriod(new DateTime('2020-01-01'), new DateInterval('P10D'), new DateTime('2020-02-01'));
var_dump($period->getRecurrences()); // NULL

$period = new DatePeriod(new DateTime('2020-01-01'), new DateInterval('P10D'), 4);
var_dump($period->getRecurrences()); // int(4)

```

### DatePeriod::getStartDate

```php
<?php

$period = new DatePeriod(new DateTime('2020-01-01'), new DateInterval('P10D'), new DateTime('2020-02-01'));
var_dump($period->getStartDate()); // object(DateTime)#4 (3) { ["date"]=> string(26) "2020-01-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

## Date / Time

### checkdate

```php
<?php

var_dump(checkdate(12, 31, 2020)); // bool(true)
var_dump(checkdate(2, 29, 2019));  // bool(false)

```

### date_add

```php
<?php

var_dump(date_add(new DateTime('2020-01-01 23:59:59'), new DateInterval('P10D'))); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-11 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### date_create_from_format

```php
<?php

var_dump(date_create_from_format('Y-m-d H:i:s', '2020-01-01 23:59:59')); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### date_create_immutable_from_format

```php
<?php

var_dump(date_create_immutable_from_format('Y-m-d H:i:s', '2020-01-01 23:59:59')); // object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2020-01-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### date_create_immutable

```php
<?php

var_dump(date_create_immutable('+1 day'));   // object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2020-05-13 07:22:29.234731" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(date_create_immutable('-1 day'));   // object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2020-05-11 07:22:29.234745" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(date_create_immutable('+1 month')); // object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2020-06-12 07:22:29.234752" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### date_create

```php
<?php

var_dump(date_create('2020-01-01'));          // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(date_create('2020-01-01 23:59:59')); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(date_create('now'));

```

### date_date_set

```php
<?php

var_dump(date_date_set(new DateTime('2020-01-01 23:59:59'), 2020, 2, 1)); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-02-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(date_date_set(new DateTime('2020-01-01 23:59:59'), 2020, 3, 1)); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-03-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### date_default_timezone_get

```php
<?php

var_dump(date_default_timezone_get());

```

### date_default_timezone_set

```php
<?php

var_dump(date_default_timezone_set('UTC')); // bool(true)
var_dump(date_default_timezone_set('PRC')); // bool(true)

```

### date_diff

```php
<?php

var_dump(date_diff(new DateTime('2020-01-01 23:59:59'), new DateTime('2020-02-01 23:59:59'))); // object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(1) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(31) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }

```

### date_format

```php
<?php

var_dump(date_format(new DateTime('2020-01-01 23:59:59'), 'Y-m-d')); // string(10) "2020-01-01"

```

### date_get_last_errors

```php
<?php

var_dump(date_get_last_errors()); // bool(false)

```

### date_interval_create_from_date_string

```php
<?php

var_dump(date_interval_create_from_date_string('1 day'));   // object(DateInterval)#1 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(1) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }
var_dump(date_interval_create_from_date_string('2 weeks')); // object(DateInterval)#1 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(14) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }
var_dump(date_interval_create_from_date_string('3 month')); // object(DateInterval)#1 (16) { ["y"]=> int(0) ["m"]=> int(3) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }
var_dump(date_interval_create_from_date_string('4 years')); // object(DateInterval)#1 (16) { ["y"]=> int(4) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }

```

### date_interval_format

```php
<?php

var_dump(date_interval_format(new DateInterval('P2Y4DT6H8M'), '%y years'));   // string(7) "2 years"
var_dump(date_interval_format(new DateInterval('P2Y4DT6H8M'), '%d days'));    // string(6) "4 days"
var_dump(date_interval_format(new DateInterval('P2Y4DT6H8M'), '%h hours'));   // string(7) "6 hours"
var_dump(date_interval_format(new DateInterval('P2Y4DT6H8M'), '%i minutes')); // string(9) "8 minutes"

```

### date_isodate_set

```php
<?php

var_dump(date_isodate_set(new DateTime('2020-01-01 23:59:59'), 2020, 1));    // object(DateTime)#1 (3) { ["date"]=> string(26) "2019-12-30 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(date_isodate_set(new DateTime('2020-01-01 23:59:59'), 2020, 2));    // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-06 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(date_isodate_set(new DateTime('2020-01-01 23:59:59'), 2020, 2, 2)); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-07 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### date_modify

```php
<?php

var_dump(date_modify(new DateTime('2020-01-01 23:59:59'), '+1 day'));   // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-02 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(date_modify(new DateTime('2020-01-01 23:59:59'), '-1 day'));   // object(DateTime)#1 (3) { ["date"]=> string(26) "2019-12-31 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(date_modify(new DateTime('2020-01-01 23:59:59'), '+1 month')); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-02-01 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### date_offset_get

```php
<?php

var_dump(date_offset_get(new DateTime('2020-01-01 23:59:59')));

```

### date_parse_from_format

```php
<?php

var_dump(date_parse_from_format('Y-m-d', '2020-01-01'));                // array(12) { ["year"]=> int(2020) ["month"]=> int(1) ["day"]=> int(1) ["hour"]=> bool(false) ["minute"]=> bool(false) ["second"]=> bool(false) ["fraction"]=> bool(false) ["warning_count"]=> int(0) ["warnings"]=> array(0) { } ["error_count"]=> int(0) ["errors"]=> array(0) { } ["is_localtime"]=> bool(false) }
var_dump(date_parse_from_format('Y-m-d H:i:s', '2020-01-01 23:59:59')); // array(12) { ["year"]=> int(2020) ["month"]=> int(1) ["day"]=> int(1) ["hour"]=> int(23) ["minute"]=> int(59) ["second"]=> int(59) ["fraction"]=> float(0) ["warning_count"]=> int(0) ["warnings"]=> array(0) { } ["error_count"]=> int(0) ["errors"]=> array(0) { } ["is_localtime"]=> bool(false) }

```

### date_parse

```php
<?php

var_dump(date_parse('2020-01-01'));          // array(12) { ["year"]=> int(2020) ["month"]=> int(1) ["day"]=> int(1) ["hour"]=> bool(false) ["minute"]=> bool(false) ["second"]=> bool(false) ["fraction"]=> bool(false) ["warning_count"]=> int(0) ["warnings"]=> array(0) { } ["error_count"]=> int(0) ["errors"]=> array(0) { } ["is_localtime"]=> bool(false) }
var_dump(date_parse('2020-01-01 23:59:59')); // array(12) { ["year"]=> int(2020) ["month"]=> int(1) ["day"]=> int(1) ["hour"]=> int(23) ["minute"]=> int(59) ["second"]=> int(59) ["fraction"]=> float(0) ["warning_count"]=> int(0) ["warnings"]=> array(0) { } ["error_count"]=> int(0) ["errors"]=> array(0) { } ["is_localtime"]=> bool(false) }

```

### date_sub

```php
<?php

var_dump(date_sub(new DateTime('2020-01-01 23:59:59'), new DateInterval('P10D'))); // object(DateTime)#1 (3) { ["date"]=> string(26) "2019-12-22 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### date_sun_info

```php
<?php

var_dump(date_sun_info(time(), 31.7667, 35.2333));

```

### date_sunrise

```php
<?php

var_dump(date_sunrise(time()));
var_dump(date_sunrise(time(), SUNFUNCS_RET_STRING));
var_dump(date_sunrise(time(), SUNFUNCS_RET_STRING, 31.7667, 35.2333));

```

### date_sunset

```php
<?php

var_dump(date_sunset(time()));
var_dump(date_sunset(time(), SUNFUNCS_RET_STRING));
var_dump(date_sunset(time(), SUNFUNCS_RET_STRING, 31.7667, 35.2333));

```

### date_time_set

```php
<?php

var_dump(date_time_set(new DateTime('2020-01-01 23:59:59'), 0, 0, 0)); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(date_time_set(new DateTime('2020-01-01 23:59:59'), 1, 0, 0)); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-01 01:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### date_timestamp_get

```php
<?php

var_dump(date_timestamp_get(new DateTime('2020-01-01 23:59:59'))); // int(1577923199)

```

### date_timestamp_set

```php
<?php

var_dump(date_timestamp_set(new DateTime('2020-01-01 23:59:59'), time()));

```

### date_timezone_get

```php
<?php

var_dump(date_timezone_get(new DateTime('2020-01-01 23:59:59'))); // object(DateTimeZone)#2 (2) { ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

```

### date_timezone_set

```php
<?php

var_dump(date_timezone_set(new DateTime('2020-01-01 23:59:59'), new DateTimezone('PRC'))); // object(DateTime)#1 (3) { ["date"]=> string(26) "2020-01-02 07:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "PRC" }

```

### date

```php
<?php

var_dump(date('Y-m-d'));
var_dump(date('Y-m-d H:i:s'));
var_dump(date('Y-m-d H:i:s', time()));

```

### getdate

```php
<?php

var_dump(getdate());
var_dump(getdate(time()));

```

### gettimeofday

```php
<?php

var_dump(gettimeofday());
var_dump(gettimeofday(true));

```

### gmdate

```php
<?php

var_dump(gmdate('Y-m-d'));
var_dump(gmdate('Y-m-d', time()));

```

### gmstrftime

```php
<?php

var_dump(gmstrftime('%Y-%m-%d'));

```

### idate

```php
<?php

var_dump(idate('Y'));
var_dump(idate('m'));
var_dump(idate('d'));

```

### localtime

```php
<?php

var_dump(localtime());
var_dump(localtime(time()));

```

### microtime

```php
<?php

var_dump(microtime());
var_dump(microtime(true));

```

### strftime

```php
<?php

var_dump(strftime('%Y-%m-%d'));
var_dump(strftime('%Y-%m-%d', time()));

```

### strtotime

```php
<?php

var_dump(strtotime(date('Y-m-d')));
var_dump(strtotime(date('Y-m-d H:i:s')));

```

### time

```php
<?php

var_dump(time());

```

### timezone_abbreviations_list

```php
<?php

var_dump(timezone_abbreviations_list());

```

### timezone_identifiers_list

```php
<?php

var_dump(timezone_identifiers_list());

```

### timezone_location_get

```php
<?php

var_dump(timezone_location_get(new DateTimeZone('Europe/London'))); // array(4) { ["country_code"]=> string(2) "GB" ["latitude"]=> float(51.50833) ["longitude"]=> float(-0.12528) ["comments"]=> string(0) "" }

```

### timezone_name_from_abbr

```php
<?php

var_dump(timezone_name_from_abbr('CET'));       // string(13) "Europe/Berlin"
var_dump(timezone_name_from_abbr('', 3600, 0)); // string(12) "Europe/Paris"

```

### timezone_name_get

```php
<?php

var_dump(timezone_name_get(new DateTimeZone('Europe/London'))); // string(13) "Europe/London"

```

### timezone_offset_get

```php
<?php

var_dump(timezone_offset_get(new DateTimeZone('Europe/London'), new DateTime('now')));

```

### timezone_open

```php
<?php

var_dump(timezone_open('UTC')); // object(DateTimeZone)#1 (2) { ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
var_dump(timezone_open('PRC')); // object(DateTimeZone)#1 (2) { ["timezone_type"]=> int(3) ["timezone"]=> string(3) "PRC" }

```

### timezone_transitions_get

```php
<?php

var_dump(timezone_transitions_get(new DateTimeZone('Europe/London')));

```

### timezone_version_get

```php
<?php

var_dump(timezone_version_get());

```

