php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41912 date() interprets Unix timestamp as GMT and converts it to the default timezone
Submitted: 2007-07-06 08:21 UTC Modified: 2007-07-11 21:02 UTC
From: ron@php.net Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.3 OS: Debian GNU/Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ron@php.net
New email:
PHP Version: OS:

 

 [2007-07-06 08:21 UTC] ron@php.net
Description:
------------
date() interprets a Unix timestamp as GMT and converts it to the default timezone. In my opinion it should not convert timezones.

(bug report requested by Derick Rethans).

Reproduce code:
---------------
<?php

date_default_timezone_set('Europe/Amsterdam');

$date = new DateTime('now', new DateTimeZone('GMT'));

echo 'DateTime::format(): '.$date->format('Ymd, H:i:s')."\n";
echo 'date() of unixtime: '.date('Ymd, H:i:s', $date->format('U'))."\n";

?>

Expected result:
----------------
DateTime::format(): 20070706, 07:38:45
date() of unixtime: 20070706, 07:38:45


Actual result:
--------------
DateTime::format(): 20070706, 07:38:45
date() of unixtime: 20070706, 09:38:45


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-11 21:02 UTC] derick@php.net
I checked this now, and it is not a bug. If you convert to a timestamp there is no more associated timezone possible. The date object keeps this normally - but it's impossible to attach this just to a number.

If you add the timezone as output, you will see the difference:

<?php

date_default_timezone_set('Europe/Amsterdam');

$date = new DateTime('now', new DateTimeZone('GMT'));

echo 'DateTime::format(): '.$date->format('Ymd, H:i:s T')."\n";
echo 'date() of unixtime: '.date('Ymd, H:i:s T', $date->format('U'))."\n";

?>

derick@kossu:~$ php bug41912.php
DateTime::format(): 20070711, 21:00:26 UTC
date() of unixtime: 20070711, 23:00:26 CEST

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Apr 02 10:01:30 2025 UTC