Download the PHP package krixon/datetime without Composer
On this page you can find all versions of the php package krixon/datetime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package datetime
datetime
PHP7 date/time library.
Prerequisites
- PHP 7.0+
Installation
Install via composer
To install datetime with Composer, run the following command:
You can see this library on Packagist.
Install from source
Introduction
This library is a layer on top of PHP's built-in date and time classes which provides additional functionality
and improvements such as microsecond precision and immutability (without the inconsistencies between \DateTime,
\DateTimeImmutable and DateTimeInterface).
Creating Dates
There are various ways to create a new DateTime instance.
Using the current time and default timezone:
Using a UNIX timestamp:
Parsing a string using a specified format:
Parsing a string containing any supported date and time format:
Using an existing built-in \DateTime instance:
Using an existing \IntlCalendar instance:
Modifying Dates
All DateTime instances are immutable. However methods are provided for creating new instances with modifications
applied.
Adjusting the date:
If you are making many changes to a DateTime without needing the intermediate objects, you can use the
DateTimeCalculator class. This supports all of the operations you can do on a DateTime object itself but without
the overhead of creating new objects which are then thrown away.
For example, imagine you want to add an interval to a base date a number of times, but you are only interested in
the final result. While you could call $date = $date->add('PT1D') repeatedly, a more efficient method would be:
Of course this is a contrived example and in reality you would just call $date = $date->add('PT50D'), but there
are many arithmetic operations you can perform with the calculator which cannot necessarily be achieved as efficiently
using just the DateTime API.
