Using Predefined Constants for Date Format

suggest change

We can use Predefined Constants for Date format in date() instead of the conventional date format strings since PHP 5.1.0.


Predefined Date Format Constants Available

DATE_ATOM - Atom (2016-07-22T14:50:01+00:00)

DATE_COOKIE - HTTP Cookies (Friday, 22-Jul-2016 14:50:01 UTC)

DATE_RSS - RSS (Fri, 22 Jul 2016 14:50:01 +0000)

DATE_W3C - World Wide Web Consortium (2016-07-22T14:50:01+00:00)

DATE_ISO8601 - ISO-8601 (2016-07-22T14:50:01+0000). PHP’s offset has no colon, so this is not strict ISO-8601.

DATE_RFC822 - RFC 822 (Fri, 22 Jul 16 14:50:01 +0000)

DATE_RFC850 - RFC 850 (Friday, 22-Jul-16 14:50:01 UTC)

DATE_RFC1036 - RFC 1036 (Fri, 22 Jul 16 14:50:01 +0000)

DATE_RFC1123 - RFC 1123 (Fri, 22 Jul 2016 14:50:01 +0000)

DATE_RFC2822 - RFC 2822 (Fri, 22 Jul 2016 14:50:01 +0000)

DATE_RFC3339 - Same as DATE_ATOM (2016-07-22T14:50:01+00:00)


Usage Examples

echo date(DATE_RFC822);

This prints the current time in that format, for example Fri, 22 Jul 16 14:50:01 +0000.

echo date(DATE_ATOM,mktime(0,0,0,8,15,1947));

mktime() uses the default timezone. In UTC the result is 1947-08-15T00:00:00+00:00.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents