Oihana PHP Standards

DateFormat extends Iso8601Format

Standard date and time format patterns from various sources.

Extends Iso8601Format and adds non-ISO formats commonly used in the wild: IETF RFC date formats, the HTTP date format (RFC 7231), SQL/database literal formats and the Unix timestamp.

Because this class inherits all ISO 8601 constants, it acts as a single entry point for any date-time format the project understands.

RFC 3339 and ATOM are intentionally not redeclared here: their PHP pattern (Y-m-d\TH:i:sP) is identical to Iso8601Format::DATE_TIME, and RFC 3339 with fractional seconds matches Iso8601Format::DATE_TIME_MILLI / Iso8601Format::DATE_TIME_MICRO. Reusing these constants keeps getConstant() reverse-lookup deterministic.

Example usage:

use org\common\DateFormat;

$dt = new DateTimeImmutable('2026-05-14 08:15:30', new DateTimeZone('+02:00'));

echo $dt->format( DateFormat::RFC2822 );  // "Thu, 14 May 2026 08:15:30 +0200"
echo $dt->format( DateFormat::RFC7231 );  // "Thu, 14 May 2026 06:15:30 GMT"
echo $dt->format( DateFormat::MYSQL );    // "2026-05-14 08:15:30"

// ISO constants are also available via inheritance:
echo $dt->format( DateFormat::DATE_TIME_ZULU ) ;

DateFormat::includes( Iso8601Format::DATE ) ;     // true (inherited)
DateFormat::getConstant('D, d M Y H:i:s O') ;     // "RFC2822"
Tags
link

RFC 2822 (Internet Message Format)

RFC 7231 (HTTP/1.1 Semantics)

author

Marc Alcaraz (ekameleon)

since
1.0.2

Table of Contents

Constants

COOKIE  : string = 'l, d-M-Y H:i:s T'
Cookie expiration date (HTTP cookies, RFC 6265): `l, d-M-Y H:i:s T` (e.g. "Thursday, 14-May-2026 08:15:30 UTC").
DATE  : string = 'Y-m-d'
Calendar date in extended format: `Y-m-d` (e.g. "2026-05-14").
DATE_BASIC  : string = 'Ymd'
Calendar date in basic format: `Ymd` (e.g. "20260514").
DATE_TIME  : string = 'Y-m-d\TH:i:sP'
Date and time in extended format with timezone offset: `Y-m-d\TH:i:sP` (e.g. "2026-05-14T08:15:30+02:00").
DATE_TIME_BASIC  : string = 'Ymd\THisO'
Date and time in basic format with offset: `Ymd\THisO` (e.g. "20260514T081530+0200").
DATE_TIME_BASIC_ZULU  : string = 'Ymd\THis\Z'
Date and time in basic format in UTC ("Zulu"): `Ymd\THis\Z` (e.g. "20260514T081530Z").
DATE_TIME_LOCAL  : string = 'Y-m-d\TH:i:s'
Local date and time in extended format, without timezone: `Y-m-d\TH:i:s` (e.g. "2026-05-14T08:15:30").
DATE_TIME_MICRO  : string = 'Y-m-d\TH:i:s.uP'
Date and time with microseconds and timezone offset: `Y-m-d\TH:i:s.uP` (e.g. "2026-05-14T08:15:30.123456+02:00").
DATE_TIME_MICRO_ZULU  : string = 'Y-m-d\TH:i:s.u\Z'
Date and time with microseconds in UTC ("Zulu"): `Y-m-d\TH:i:s.u\Z` (e.g. "2026-05-14T08:15:30.123456Z").
DATE_TIME_MILLI  : string = 'Y-m-d\TH:i:s.vP'
Date and time with milliseconds and timezone offset: `Y-m-d\TH:i:s.vP` (e.g. "2026-05-14T08:15:30.123+02:00").
DATE_TIME_MILLI_ZULU  : string = 'Y-m-d\TH:i:s.v\Z'
Date and time with milliseconds in UTC ("Zulu"): `Y-m-d\TH:i:s.v\Z` (e.g. "2026-05-14T08:15:30.123Z").
DATE_TIME_ZULU  : string = 'Y-m-d\TH:i:s\Z'
Date and time in extended format in UTC ("Zulu"): `Y-m-d\TH:i:s\Z` (e.g. "2026-05-14T08:15:30Z").
MYSQL  : string = 'Y-m-d H:i:s'
MySQL / SQLite `DATETIME` literal: `Y-m-d H:i:s` (e.g. "2026-05-14 08:15:30"). Note the space separator instead of `T`.
ORDINAL_DATE  : string = 'Y-z'
ISO 8601 ordinal date: `Y-z` (e.g. "2026-134").
RFC1036  : string = 'D, d M y H:i:s O'
RFC 1036 Usenet date: `D, d M y H:i:s O` (same as RFC 822).
RFC1123  : string = 'D, d M Y H:i:s O'
RFC 1123 date (modern email/HTTP, 4-digit year): `D, d M Y H:i:s O` (e.g. "Thu, 14 May 2026 08:15:30 +0200").
RFC2822  : string = 'D, d M Y H:i:s O'
RFC 2822 Internet Message Format date: `D, d M Y H:i:s O` (e.g. "Thu, 14 May 2026 08:15:30 +0200").
RFC7231  : string = 'D, d M Y H:i:s \G\M\T'
RFC 7231 HTTP-date (IMF-fixdate, always GMT): `D, d M Y H:i:s \G\M\T` (e.g. "Thu, 14 May 2026 06:15:30 GMT"). The value must be converted to UTC by the caller before formatting.
RFC822  : string = 'D, d M y H:i:s O'
RFC 822 email date (obsolete; uses 2-digit year): `D, d M y H:i:s O` (e.g. "Thu, 14 May 26 08:15:30 +0200").
RFC850  : string = 'l, d-M-y H:i:s T'
RFC 850 Usenet date (obsolete): `l, d-M-y H:i:s T` (e.g. "Thursday, 14-May-26 08:15:30 UTC").
RSS  : string = 'D, d M Y H:i:s O'
RSS 2.0 pubDate (RFC 822 / 2822 profile): `D, d M Y H:i:s O` (e.g. "Thu, 14 May 2026 08:15:30 +0200").
TIME  : string = 'H:i:s'
Time of day in extended format, without timezone: `H:i:s` (e.g. "08:15:30").
TIME_BASIC  : string = 'His'
Time of day in basic format: `His` (e.g. "081530").
TIME_OFFSET  : string = 'H:i:sP'
Time of day with timezone offset: `H:i:sP` (e.g. "08:15:30+02:00").
TIME_ZULU  : string = 'H:i:s\Z'
Time of day in UTC ("Zulu"): `H:i:s\Z` (e.g. "08:15:30Z").
UNIX  : string = 'U'
Unix timestamp (seconds since 1970-01-01 00:00:00 UTC): `U`.
WEEK  : string = 'o-\WW'
ISO 8601 week (without day): `o-\WW` (e.g. "2026-W20").
WEEK_DATE  : string = 'o-\WW-N'
ISO 8601 week date in extended format: `o-\WW-N` (e.g. "2026-W20-4" for the 4th day of week 20 of ISO year 2026).
WEEK_DATE_BASIC  : string = 'o\WWN'
ISO 8601 week date in basic format: `o\WWN` (e.g. "2026W204").
YEAR  : string = 'Y'
Year only: `Y` (e.g. "2026").
YEAR_MONTH  : string = 'Y-m'
Year and month: `Y-m` (e.g. "2026-05").

Constants

Cookie expiration date (HTTP cookies, RFC 6265): `l, d-M-Y H:i:s T` (e.g. "Thursday, 14-May-2026 08:15:30 UTC").

public string COOKIE = 'l, d-M-Y H:i:s T'

DATE

Calendar date in extended format: `Y-m-d` (e.g. "2026-05-14").

public string DATE = 'Y-m-d'

DATE_BASIC

Calendar date in basic format: `Ymd` (e.g. "20260514").

public string DATE_BASIC = 'Ymd'

DATE_TIME

Date and time in extended format with timezone offset: `Y-m-d\TH:i:sP` (e.g. "2026-05-14T08:15:30+02:00").

public string DATE_TIME = 'Y-m-d\TH:i:sP'

DATE_TIME_BASIC

Date and time in basic format with offset: `Ymd\THisO` (e.g. "20260514T081530+0200").

public string DATE_TIME_BASIC = 'Ymd\THisO'

DATE_TIME_BASIC_ZULU

Date and time in basic format in UTC ("Zulu"): `Ymd\THis\Z` (e.g. "20260514T081530Z").

public string DATE_TIME_BASIC_ZULU = 'Ymd\THis\Z'

DATE_TIME_LOCAL

Local date and time in extended format, without timezone: `Y-m-d\TH:i:s` (e.g. "2026-05-14T08:15:30").

public string DATE_TIME_LOCAL = 'Y-m-d\TH:i:s'

DATE_TIME_MICRO

Date and time with microseconds and timezone offset: `Y-m-d\TH:i:s.uP` (e.g. "2026-05-14T08:15:30.123456+02:00").

public string DATE_TIME_MICRO = 'Y-m-d\TH:i:s.uP'

DATE_TIME_MICRO_ZULU

Date and time with microseconds in UTC ("Zulu"): `Y-m-d\TH:i:s.u\Z` (e.g. "2026-05-14T08:15:30.123456Z").

public string DATE_TIME_MICRO_ZULU = 'Y-m-d\TH:i:s.u\Z'

DATE_TIME_MILLI

Date and time with milliseconds and timezone offset: `Y-m-d\TH:i:s.vP` (e.g. "2026-05-14T08:15:30.123+02:00").

public string DATE_TIME_MILLI = 'Y-m-d\TH:i:s.vP'

DATE_TIME_MILLI_ZULU

Date and time with milliseconds in UTC ("Zulu"): `Y-m-d\TH:i:s.v\Z` (e.g. "2026-05-14T08:15:30.123Z").

public string DATE_TIME_MILLI_ZULU = 'Y-m-d\TH:i:s.v\Z'

DATE_TIME_ZULU

Date and time in extended format in UTC ("Zulu"): `Y-m-d\TH:i:s\Z` (e.g. "2026-05-14T08:15:30Z").

public string DATE_TIME_ZULU = 'Y-m-d\TH:i:s\Z'

MYSQL

MySQL / SQLite `DATETIME` literal: `Y-m-d H:i:s` (e.g. "2026-05-14 08:15:30"). Note the space separator instead of `T`.

public string MYSQL = 'Y-m-d H:i:s'

ORDINAL_DATE

ISO 8601 ordinal date: `Y-z` (e.g. "2026-134").

public string ORDINAL_DATE = 'Y-z'

Note: PHP's z format yields a zero-based day of year (0–365), whereas the ISO ordinal day is 1-based. Prefer building the string manually when strict compliance is required.

RFC1036

RFC 1036 Usenet date: `D, d M y H:i:s O` (same as RFC 822).

public string RFC1036 = 'D, d M y H:i:s O'

RFC1123

RFC 1123 date (modern email/HTTP, 4-digit year): `D, d M Y H:i:s O` (e.g. "Thu, 14 May 2026 08:15:30 +0200").

public string RFC1123 = 'D, d M Y H:i:s O'

RFC2822

RFC 2822 Internet Message Format date: `D, d M Y H:i:s O` (e.g. "Thu, 14 May 2026 08:15:30 +0200").

public string RFC2822 = 'D, d M Y H:i:s O'

RFC7231

RFC 7231 HTTP-date (IMF-fixdate, always GMT): `D, d M Y H:i:s \G\M\T` (e.g. "Thu, 14 May 2026 06:15:30 GMT"). The value must be converted to UTC by the caller before formatting.

public string RFC7231 = 'D, d M Y H:i:s \G\M\T'

RFC822

RFC 822 email date (obsolete; uses 2-digit year): `D, d M y H:i:s O` (e.g. "Thu, 14 May 26 08:15:30 +0200").

public string RFC822 = 'D, d M y H:i:s O'

RFC850

RFC 850 Usenet date (obsolete): `l, d-M-y H:i:s T` (e.g. "Thursday, 14-May-26 08:15:30 UTC").

public string RFC850 = 'l, d-M-y H:i:s T'

RSS

RSS 2.0 pubDate (RFC 822 / 2822 profile): `D, d M Y H:i:s O` (e.g. "Thu, 14 May 2026 08:15:30 +0200").

public string RSS = 'D, d M Y H:i:s O'

TIME

Time of day in extended format, without timezone: `H:i:s` (e.g. "08:15:30").

public string TIME = 'H:i:s'

TIME_BASIC

Time of day in basic format: `His` (e.g. "081530").

public string TIME_BASIC = 'His'

TIME_OFFSET

Time of day with timezone offset: `H:i:sP` (e.g. "08:15:30+02:00").

public string TIME_OFFSET = 'H:i:sP'

TIME_ZULU

Time of day in UTC ("Zulu"): `H:i:s\Z` (e.g. "08:15:30Z").

public string TIME_ZULU = 'H:i:s\Z'

UNIX

Unix timestamp (seconds since 1970-01-01 00:00:00 UTC): `U`.

public string UNIX = 'U'

WEEK

ISO 8601 week (without day): `o-\WW` (e.g. "2026-W20").

public string WEEK = 'o-\WW'

WEEK_DATE

ISO 8601 week date in extended format: `o-\WW-N` (e.g. "2026-W20-4" for the 4th day of week 20 of ISO year 2026).

public string WEEK_DATE = 'o-\WW-N'

WEEK_DATE_BASIC

ISO 8601 week date in basic format: `o\WWN` (e.g. "2026W204").

public string WEEK_DATE_BASIC = 'o\WWN'

YEAR

Year only: `Y` (e.g. "2026").

public string YEAR = 'Y'

YEAR_MONTH

Year and month: `Y-m` (e.g. "2026-05").

public string YEAR_MONTH = 'Y-m'
On this page

Search results