|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-07-27 16:35 UTC] mail at gh01 dot de
Description: ------------ ISO 8601 differentiates between local time (without time zone), UTC with letter "Z" and time offsets from UTC like "+02:00". https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators When formatting datetimes, it is sometimes desired to get the "Z" for UTC times and otherwise the offset. But at the moment there are only the formatting chars "O" (for "+0200" etc.) and "P" (for "+02:00" etc.). I suggest to add lower case "p" as another formatting char which behaves the same as upper case "P" but returns "Z" for UTC datetimes. https://github.com/php/php-src/pull/5896 Test script: --------------- <?php $datetime = new DateTime('2020-07-26 20:00:00', new DateTimeZone('UTC')); $datetime->format('Y-m-d\TH:i:sP'); // '2020-07-26T20:00:00+00:00' $datetime->format('Y-m-d\TH:i:sp'); // '2020-07-26T20:00:00Z' $datetime = new DateTime('2020-07-26 20:00:00', new DateTimeZone('Europe/London')); $datetime->format('Y-m-d\TH:i:sP'); // '2020-07-26T20:00:00+00:00' $datetime->format('Y-m-d\TH:i:sp'); // '2020-07-26T20:00:00+00:00' $datetime = new DateTime('2020-07-26 20:00:00', new DateTimeZone('Europe/Berlin')); $datetime->format('Y-m-d\TH:i:sP'); // '2020-07-26T20:00:00+02:00' $datetime->format('Y-m-d\TH:i:sp'); // '2020-07-26T20:00:00+02:00' PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 02:00:01 2025 UTC |
Characters in single quotes in the formats are case-insensitive ('t' could be t or T), characters in double quotes are case-sensitive ("T" is only T). https://www.php.net/manual/en/datetime.formats.php