php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40444 Incorrect GMT timestamp
Submitted: 2007-02-12 10:03 UTC Modified: 2007-02-12 11:17 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: andreas dot braun at netcologne dot de Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.1 OS: Win XP Pro / Suse 9.1
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: andreas dot braun at netcologne dot de
New email:
PHP Version: OS:

 

 [2007-02-12 10:03 UTC] andreas dot braun at netcologne dot de
Description:
------------
REFERS TO THE FOLLOWING PHP VERSIONS: 
Windows: 4.3.8       Linux: 4.3.8
         4.4.4
         5.0.0
         5.1.6
         5.2.1

1. My Wndows PC uses as local time CET (GMT+01:00 Amsterdam, Berlin, Bern Rome ....) for Germany and my Linux PC uses CET too. 
So if we have 09:11:08(CET) GMT is 08:11:08. But gmmktime() returns under PHP 4.3.8, 4.4.4 and 5.0.0 a timestamp for 10:11:08. That's wrong!
With 5.1.6 and 5.2.1 gmmktime() returns the same value as mktime() and dsttime is now 1 instead of 0.
That's wrong, too!


Reproduce code:
---------------
<?php
echo time();
echo "\n";

$var1 = gmmktime();
echo "GMT:\t $var1";
echo "\n";

$var2 = mktime();
echo "Local:\t $var2";
echo "\n";

$gmdate     = date("d.m.Y - H:i:s", $var1);
$localdate  = date("d.m.Y - H:i:s", $var2);

echo "GMT-Time: $gmdate\n";
echo "Local-Time: $localdate";

echo "\n";
print_r(gettimeofday());

?>

Actual result:
--------------
***********************************************************
UNDER WIN XP with CET(GMT+01) as local time AND PHP 5.0.0

C:\Inetpub\wwwroot\cacti>php-cgi -v
PHP 5.0.0 (cgi-fcgi) (built: Jul 13 2004 21:39:41)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.0, Copyright (c) 1998-2004 Zend Technologies

C:\Inetpub\wwwroot\cacti>php-cgi date.php
Content-type: text/html
X-Powered-By: PHP/5.0.0

1171234727
GMT:    1171238327            ****** <- THIS IS WRONG!
Local:  1171234727
GMT-Time: 12.02.2007 - 00:58:47
Local-Time: 11.02.2007 - 23:58:47
Array
(
    [sec] => 1171234727       ****** <- THIS IS CORRECT!
    [usec] => 126785          ****** <- THIS IS CORRECT!
    [minuteswest] => -60      ****** <- THIS IS CORRECT!
    [dsttime] => 1
)

C:\Inetpub\wwwroot\cacti>
***********************************************************


***********************************************************
UNDER WIN XP with CET(GMT+01) as local time AND PHP 5.2.1

C:\Inetpub\wwwroot\cacti>php -v
PHP 5.2.1 (cli) (built: Feb  7 2007 23:11:26)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

C:\Inetpub\wwwroot\cacti>php date.php
1171235055
GMT:    1171235055          ****** <- THIS IS WRONG!
Local:  1171235055
GMT-Time: 12.02.2007 - 00:04:15
Local-Time: 12.02.2007 - 00:04:15
Array
(
    [sec] => 1171235055     ****** <- THIS IS CORRECT!
    [usec] => 524359        ****** <- THIS IS CORRECT!
    [minuteswest] => -60    ****** <- THIS IS CORRECT!
    [dsttime] => 0
)

C:\Inetpub\wwwroot\cacti>
***********************************************************


***********************************************************
UNDER SUSE 9.1 with CET(GMT+01) as local time AND PHP 4.3.8

dev3:/thishost/unix/cen/cacti/plugins # php date.php
1171267868
GMT:     1171271468         ****** <- THIS IS WRONG!
Local:   1171267868
GMT-Time: 12.02.2007 - 10:11:08
Local-Time: 12.02.2007 - 09:11:08
Array
(
    [sec] => 1171267868     ****** <- THIS IS CORRECT!
    [usec] => 455367        ****** <- THIS IS CORRECT!
    [minuteswest] => -60    ****** <- THIS IS CORRECT!
    [dsttime] => 0
)
dev3:/thishost/unix/cen/cacti/plugins # date
Mon Feb 12 09:11:13 CET 2007
***********************************************************

SO, THE RESULT IS WRONG GMT-TIME HAS TO BE 08:11:08 RESPECTIVELY 1171264268

***********************************************************

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-12 10:17 UTC] tony2001@php.net
Set correct timezone using date.timezone.
More details: http://www.php.net/manual/en/function.date-default-timezone-set.php
 [2007-02-12 11:05 UTC] andreas dot braun at netcologne dot de
This function is only available for PHP 5.1.0 and higher - So, its no solution for 4.x! And this is no explanation why the value of "minuteswest" is correct with "-60", because Germany lies 60 minutes in the east of Greenwich.

But the result of gmmktime() is wrong. Looks more like an internal fault of using signs.
 [2007-02-12 11:17 UTC] tony2001@php.net
>This function is only available for PHP 5.1.0 and higher -
> So, its no solution for 4.x!
The solution is to upgrade to PHP5, that's what new versions are made for.

>And this is no explanation why the value of "minuteswest"
> is correct with "-60", 
You did not set the timezone.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 27 21:00:03 2025 UTC