Download the PHP package minphp/date without Composer
On this page you can find all versions of the php package minphp/date. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package date
Short Description Date Library
License MIT
Homepage http://github.com/phillipsdata/minphp-date
Informations about the package date
Minphp/Date
Date manipulation library.
Installation
Install via composer:
Basic Usage
Instantiation
You may optionally define custom datetime formats and from/to timezones for dates during instantiation. However, they can be defined separately when setting datetime formats.
Setting Timezones
Timezones can be set during instantiation or via ::setTimezone. Not setting a set of from/to timezones will use the system's defined timezone unless the given date contains timezone information.
Setting Datetime Formats
Date formats can be set on the object to simplify calls when formatting dates.
The following date formats are available by default, but can be overridden, or added to, using this method:
Formatting a Date
Dates can be formatted by specifying your own php date format or by using one of the predefined formats.
To format a date by specifying your own date format, use Date::format:
To format a date via a predefined format or by specifying your own date format, use Date::cast:
Formatting a date respects the set timezones:
Modifying and Formatting a Date
A date can be modified by adding/subtracting time using the strtotime-compatible Date and Time formats.
The date returned is also formatted according to Formatting a Date.
For dates that are modified such that they will cross daylight savings in either the from or to timezones, you should include a relative from timezone when you want to maintain a consistent time-of-day. This is necessary if your from timezone differs from the relative timezone of the date you are modifying across daylight savings.
Consider:
Modifying dates with respect to one timezone will maintain a consistent time-of-day despite the daylight savings offset changing.
Retrieving a Date Range
A set of months or years can be generated. The dates are created from the current server time in the defined from timezone.
Generating Months
Output:
The month range and key/value format can be specified:
Output:
Generating Years
Output:
The year key/value format can be specified:
Output:
Generating a Date Range
A date range can be generated between two given dates, and formatted according to the given formatting rules. The dates are created from the current server time in the defined from timezone.
The following date range formats are used by default, but can be overridden:
Retrieving a Unix Timestamp
A Unix Timestamp can be retrieved from a date via strtotime. However, the method considers the system's timezone--not the defined from timezone--for the timestamp conversion.