DateTime

DateTime and DateTimeImmutable is a class for the representation of date and time. It has two variants: DateTimeImmutable cannot be modified after creation, while DateTime can.

Both classes comes with the DateTimeInterface, for typing purposes.

DateTime objects may be created with the constructor, and with several specific methods, such as createFromInterface, createFromFormat or createFromImmutable.

<?php

    $date = new DateTimeImmutable('2024-02-24 11:45 America/Montreal');

    $mutable = DateTime::createFromInterface($date);

    $date = new DateTime('2014-06-20 11:45 Europe/Amsterdam');

?>

Documentation

See also The DateTime Class, Dates and periods in PHP and Tokei is a new PHP library dedicated to time-of-day.

Related : Dates, Calendar, DateInterval, Days Are Not 86400 Seconds, Micro-second, Clock, Datetime Trap, DateTimeInterface

Related packages : bakame/tokei, nesbot/carbon, cakephp/chronos, brick/date-time