Skip to content

Evalute U-timestamp in createFromFormat as GMT timestamp #16277

Open
@kylekatarnls

Description

@kylekatarnls

Description

The following code:

<?php
echo DateTime::createFromFormat('U e', '1730597400 America/Toronto')->format('U');

Resulted in this output:

1730615400

It's 5 hours more than the input timestamp.

But I expected this output instead:

1730597400

The difference matches the timezone offset.

But documentation on createFromFormat about U says:

Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

GMT is specified, so I expect the timestamp to be constant whatever is the timezone.

I.E. I expect DateTime::createFromFormat('U e', '1730597400 America/Toronto') to be equivalent to:

$date = DateTime::createFromFormat('U', '1730597400');
$date->setTimezone(new DateTimeZone('America/Toronto'));

PHP Version

PHP 8.3.12

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions