Skip to content

Dates Created from Strings with Timezone Offsets Aren't Properly Formatted When Using 'p' #10447

Closed

Description

@dustinwilson

Description

The following code:

<?php
$date = new \DateTimeImmutable('2023-01-25T00:00:00+00:00');
echo $date->format('Y-m-d\TH:i:sp');

Resulted in this output:

2023-01-25T00:00:00+00:00

But I expected this output instead:

2023-01-25T00:00:00Z

PHP Version

8.2.1

Operating System

MacOS Monterey (12.6.3)

Activity

  1. hormus commented on Jan 26, 2023

    @hormus

    Currently support p is with timezone type 3 or type 2 "UTC" or explicit "Z" https://php.watch/versions/8.0/date-utc-p-format :)

    <?php
    
    date_default_timezone_set('Europe/Berlin');
    $date = new \DateTime('2023-01-25T00:00:00');
    echo $date->format('p');
    
    ?>

    For missing offset is default offset:
    Expected result: +01:00
    For explicit offset +00:00
    Expected result: +00:00
    Or !localtime
    a6e3ce4#diff-975ac482adc74b487c6ac9d8dde32153e4b8a803ef8ec41e8d6594f0a042db69R715
    Expected result with p and timezone UTC
    $date2 = new DateTime('now', new DateTimeZone('UTC'));
    echo $date2->format('p'); // Z

  2. derickr commented on Jan 26, 2023

    @derickr
    Member

    @damianwadley Why did you change this to "Verified" — I see no triage report as to why this issue occurs, and whether this is an issue at all.

  3. damianwadley commented on Jan 26, 2023

    @damianwadley
    Member

    I assumed it had been verified because the "needs triage" was removed. Though I did briefly confirm that "p" wasn't outputting just Z which it's documented to do.

  4. added 2 commits that reference this issue on Jan 31, 2023
    a42bf93
    d17175c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions