PHP 8.0: New p date format for UTC Z time zone designation

Version8.0
TypeNew Feature

There is a new date format introduced in PHP 8.0: p. This new lower case "p" date format behaves similar to the upper case P, which shows the time zone offset. The difference between P and p format is that the new p format uses Z for UTC time, while the P format uses +00:00.

The ISO 8601 date format permits UTC time with +00:00 format, or with Z. This means both date formats below are valid:

  • 2020-09-09T20:42:34+00:00
  • 2020-09-09T20:42:34Z

With the new p date formatter, it is now possible to create a date with the second pattern above as well:

date('Y-m-d\TH:i:sp');

Here is a quick list of PHP ISO8601-related date formats:

<PHP 8.0 >=PHP 8.0
DateTimeInterface::ATOM
DATE_ATOM
Valid ISO 8601 date format.
2020-09-09T20:42:34+00:00 2020-09-09T20:42:34+00:00
c
Valid ISO 8601 date format.
2020-09-09T20:42:34+00:00 2020-09-09T20:42:34+00:00
P +00:00 +00:00
p
p is new in PHP 8.0
p +00:00
Y-m-d\TH:i:sP
Valid ISO 8601 date format. Same as c and DATE_ATOM
2020-09-09T20:42:34+00:00 2020-09-09T20:42:34+00:00
Y-m-d\TH:i:sp
p is new in PHP 8.0
2020-09-09T20:42:34p 2020-09-09T20:42:34+00:00

Dates formatted with +00:00 to indicate UTC times are perfectly valid. Quoting from Wikipedia:

An offset of zero, in addition to having the special representation "Z", can also be stated numerically as "+00:00", "+0000", or "+00".

Backwards Compatibility Impact

UTC offsets indicated with +00:00 is perfectly valid ISO 8601 date formats. If it is absolutely necessary to use Z instead of of +00:00 for UTC time, the new p format can be helpful.

While it is not possible to backport the formatter itself, a simple string-replace hack could achieve the same results as PHP 8.0 in all PHP versions since 5:

str_replace('+00:00', 'Z', date('c'));

Implementation