日期与时间
- DateTime
- DateTime::__construct - 返回一个新的 DateTime 对象
- DateTime::add - 给一个 DateTime 对象增加一定量的天,月,年,小时,分钟以及秒
- DateTime::createFromFormat - 根据给定的格式解析日期时间字符串
- DateTime::createFromImmutable - 返回封装给定 DateTimeImmutable 对象的新 DateTime 对象
- DateTime::getLastErrors - 获取警告和错误信息
- DateTime::modify - 修改日期时间对象的值
- DateTime::setDate - 设置 DateTime 对象的日期
- DateTime::setISODate - 设置 ISO 日期
- DateTime::setTime - 设置 DateTime 对象的时间
- DateTime::setTimestamp - 以 Unix 时间戳的方式设置 DateTime 对象
- DateTime::setTimezone - 设置 DateTime 对象的时区
- DateTime::sub - 对一个 DateTime 对象减去一定量的日,月,年,小时,分钟以及秒
- DateTimeImmutable
- DateTimeImmutable::__construct - 返回新的 DateTimeImmutable 对象
- DateTimeImmutable::add - 增加一定量的天,月,年,小时,分钟和秒
- DateTimeImmutable::createFromFormat - 根据指定格式解析时间字符串
- DateTimeImmutable::createFromMutable - 返回封装给定 DateTime 对象的新 DateTimeImmutable 对象
- DateTimeImmutable::getLastErrors - 返回警告和错误
- DateTimeImmutable::modify - 创建一个具有修改后的时间戳的新对象
- DateTimeImmutable::setDate - 设定日期
- DateTimeImmutable::setISODate - 设定 ISO 日期
- DateTimeImmutable::setTime - 设定时间
- DateTimeImmutable::setTimestamp - 根据 Unix 时间戳设置日期和时间
- DateTimeImmutable::setTimezone - 设置时区
- DateTimeImmutable::sub - 减去一定量的天,月,年,小时,分钟和秒
- DateTimeInterface
- DateTimeZone
- DateTimeZone::__construct - 创建新的 DateTimeZone 对象
- DateTimeZone::getLocation - 返回与时区相关的定位信息
- DateTimeZone::getName - 返回时区名称
- DateTimeZone::getOffset - 返回相对于 GMT 的时差
- DateTimeZone::getTransitions - 返回时区的所有转换
- DateTimeZone::listAbbreviations - 返回一个包含夏令时,时差和时区信息的关联数组
- DateTimeZone::listIdentifiers - 返回一个包含了所有时区标示符的索引数组
- DateInterval
- DatePeriod
- Date / Time
- checkdate - 验证一个格里高里日期
- date_add - 给一个 DateTime 对象增加一定量的天,月,年,小时,分钟以及秒
- date_create_from_format - 根据给定的格式解析日期时间字符串
- date_create_immutable_from_format - 根据指定格式解析时间字符串
- date_create_immutable - 返回新的 DateTimeImmutable 对象
- date_create - 返回一个新的 DateTime 对象
- date_date_set - 设置 DateTime 对象的日期
- date_default_timezone_get - 取得一个脚本中所有日期时间函数所使用的默认时区
- date_default_timezone_set - 设定用于一个脚本中所有日期时间函数的默认时区
- date_diff - 返回两个 DateTime 对象之间的差
- date_format - 返回根据给定格式格式化的日期
- date_get_last_errors - 获取警告和错误信息
- date_interval_create_from_date_string - 从字符串的相对部分设置 DateInterval
- date_interval_format - 格式化间隔
- date_isodate_set - 设置 ISO 日期
- date_modify - 修改日期时间对象的值
- date_offset_get - 返回时区偏移量
- date_parse_from_format - 获取有关根据指定格式格式化的给定日期的信息
- date_parse - 返回具有给定日期的详细信息的关联数组
- date_sub - 对一个 DateTime 对象减去一定量的日,月,年,小时,分钟以及秒
- date_sun_info - 返回一个数组,其中包含有关日落 / 日出和暮光开始 / 结束的信息
- date_sunrise - 返回给定的日期与地点的日出时间
- date_sunset - 返回给定的日期与地点的日落时间
- date_time_set - 设置 DateTime 对象的时间
- date_timestamp_get - 获取 Unix 时间戳
- date_timestamp_set - 以 Unix 时间戳的方式设置 DateTime 对象
- date_timezone_get - 返回相对于给定 DateTime 的时区
- date_timezone_set - 设置 DateTime 对象的时区
- date - 格式化一个本地时间 / 日期
- getdate - 取得日期 / 时间信息
- gettimeofday - 取得当前时间
- gmdate - 格式化一个 GMT / UTC 日期 / 时间
- gmstrftime - 根据区域设置格式化 GMT / UTC 时间 / 日期
- idate - 将本地时间日期格式化为整数
- localtime - 取得本地时间
- microtime - 返回当前 Unix 时间戳和微秒数
- strftime - 根据区域设置格式化本地时间 / 日期
- strtotime - 将任何字符串的日期时间描述解析为 Unix 时间戳
- time - 返回当前的 Unix 时间戳
- timezone_abbreviations_list - 返回一个包含夏令时,时差和时区信息的关联数组
- timezone_identifiers_list - 返回一个包含了所有时区标示符的索引数组
- timezone_location_get - 返回与时区相关的定位信息
- timezone_name_from_abbr - 返回缩写的时区名称
- timezone_name_get - 返回时区名称
- timezone_offset_get - 返回相对于 GMT 的时差
- timezone_open - 创建新的 DateTimeZone 对象
- timezone_transitions_get - 返回时区的所有转换
- timezone_version_get - 获取 timezonedb 的版本
DateTime
DateTime::__construct
<?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
$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
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
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
var_dump(DateTime::getLastErrors()); // bool(false)
DateTime::modify
<?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
$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
$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
$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
$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->setTimestamp(time()));
DateTime::setTimezone
<?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
$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
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
$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
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
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
var_dump(DateTimeImmutable::getLastErrors()); // bool(false)
DateTimeImmutable::modify
<?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
$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
$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
$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
$date = new DateTimeImmutable('2020-01-01 23:59:59');
var_dump($date->setTimestamp(time()));
DateTimeImmutable::setTimezone
<?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
$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
$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
$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
$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
$date = new DateTime('2020-01-01 23:59:59');
var_dump($date->getTimestamp()); // int(1577923199)
DateTime::getTimezone
<?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
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
$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
$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->getName()); // string(13) "Europe/London"
DateTimeZone::getOffset
<?php
$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->getOffset(new DateTime('now')));
DateTimeZone::getTransitions
<?php
$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->getTransitions());
DateTimeZone::listAbbreviations
<?php
$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->listAbbreviations());
DateTimeZone::listIdentifiers
<?php
$timezone = new DateTimeZone('Europe/London');
var_dump($timezone->listIdentifiers());
DateInterval
DateInterval::__construct
<?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
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
$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
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
$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
$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
$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
$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
var_dump(checkdate(12, 31, 2020)); // bool(true)
var_dump(checkdate(2, 29, 2019)); // bool(false)
date_add
<?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
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
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
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
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
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
var_dump(date_default_timezone_get());
date_default_timezone_set
<?php
var_dump(date_default_timezone_set('UTC')); // bool(true)
var_dump(date_default_timezone_set('PRC')); // bool(true)
date_diff
<?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
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
var_dump(date_get_last_errors()); // bool(false)
date_interval_create_from_date_string
<?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
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
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
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
var_dump(date_offset_get(new DateTime('2020-01-01 23:59:59')));
date_parse_from_format
<?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
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
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
var_dump(date_sun_info(time(), 31.7667, 35.2333));
date_sunrise
<?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
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
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
var_dump(date_timestamp_get(new DateTime('2020-01-01 23:59:59'))); // int(1577923199)
date_timestamp_set
<?php
var_dump(date_timestamp_set(new DateTime('2020-01-01 23:59:59'), time()));
date_timezone_get
<?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
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
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
var_dump(getdate());
var_dump(getdate(time()));
gettimeofday
<?php
var_dump(gettimeofday());
var_dump(gettimeofday(true));
gmdate
<?php
var_dump(gmdate('Y-m-d'));
var_dump(gmdate('Y-m-d', time()));
gmstrftime
<?php
var_dump(gmstrftime('%Y-%m-%d'));
idate
<?php
var_dump(idate('Y'));
var_dump(idate('m'));
var_dump(idate('d'));
localtime
<?php
var_dump(localtime());
var_dump(localtime(time()));
microtime
<?php
var_dump(microtime());
var_dump(microtime(true));
strftime
<?php
var_dump(strftime('%Y-%m-%d'));
var_dump(strftime('%Y-%m-%d', time()));
strtotime
<?php
var_dump(strtotime(date('Y-m-d')));
var_dump(strtotime(date('Y-m-d H:i:s')));
time
<?php
var_dump(time());
timezone_abbreviations_list
<?php
var_dump(timezone_abbreviations_list());
timezone_identifiers_list
<?php
var_dump(timezone_identifiers_list());
timezone_location_get
<?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
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
var_dump(timezone_name_get(new DateTimeZone('Europe/London'))); // string(13) "Europe/London"
timezone_offset_get
<?php
var_dump(timezone_offset_get(new DateTimeZone('Europe/London'), new DateTime('now')));
timezone_open
<?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
var_dump(timezone_transitions_get(new DateTimeZone('Europe/London')));
timezone_version_get
<?php
var_dump(timezone_version_get());