php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39701 Strange behaviour of gmmktime
Submitted: 2006-12-01 13:34 UTC Modified: 2006-12-02 06:15 UTC
From: mgs at au dot ru Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.0 OS: Linux, Win-XP
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: mgs at au dot ru
New email:
PHP Version: OS:

 

 [2006-12-01 13:34 UTC] mgs at au dot ru
Description:
------------
In php4 this piece of code (except date_default_timezone_get) works properly (gmtime was localtime+3(Hours)) but since date/time block was rewritten (and date_default_timezone_get is born which is happen ~PHP5.1.0) mktime and gmmktime both return the same value and date_default_timezone_get returns "Europe/Moscow".
What can be wrong?


Reproduce code:
---------------
<?php
$timelocal=mktime();
$timegm=gmmktime();
echo "local=$timelocal\n";
echo "gm   =$timegm\n";
echo "local=".date("d-m-Y H:i:s",$timelocal);
echo "\n";
echo "gm   =".date("d-m-Y H:i:s",$timegm);
echo "\n";
echo date_default_timezone_get()."\n";
?>

Expected result:
----------------
local=1164979830
gm   =1164990643
local=01-12-2006 16:30:30
gm   =01-12-2006 19:30:30
Europe/Moscow

Actual result:
--------------
local=1164979830
gm   =1164979830
local=01-12-2006 16:30:30
gm   =01-12-2006 16:30:30
Europe/Moscow


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-01 19:24 UTC] iliaa@php.net
Without any parameters mktime() and gmmktime() are equivalent 
to time(). Which means the returned value will always be the 
same no matter the timezone.

To ensure that you get the desired date you need to use gmdate
() function in your code, in which case you'll see the desired 
results.
 [2006-12-02 06:13 UTC] mgs at au dot ru
I don't think so. gmmktime always treated the parameters (even if they are absent) as GMT ones.
qoute from manual
Like mktime(), arguments may be left out in order from right to left, with any omitted arguments being set to the current corresponding GMT value.
 [2006-12-02 06:15 UTC] mgs at au dot ru
Also expected results should be
local=1164979830
gm   =1164990630
local=01-12-2006 16:30:30
gm   =01-12-2006 19:30:30
Europe/Moscow
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 18 14:00:02 2025 UTC