日期与时间

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());

results matching ""

    No results matching ""