php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66903 strtotime - diff time zones
Submitted: 2014-03-14 07:31 UTC Modified: 2014-03-14 09:08 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: a dot dyudyun at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.26 OS: Debian
Private report: No CVE-ID: None
 [2014-03-14 07:31 UTC] a dot dyudyun at gmail dot com
Description:
------------
# strtotime() function with param "now" work only with UTC 
# time zone (GMT) Grinvich, but param "midnight" work with 
# local time zone

Test script:
---------------
<?php


date_default_timezone_set("Europe/Kiev");
echo "Kiev:".strtotime("now");
echo "<br><br>"; 

date_default_timezone_set("America/New_York"); 
echo "New-York:".strtotime("now");
echo "<br><br>";
date_default_timezone_set("UTC"); 
echo "UTC:".strtotime("now");
echo "<br>==========================<br>";

date_default_timezone_set("Europe/Kiev");
echo "Kiev:".strtotime("midnight");
echo "<br><br>";

date_default_timezone_set("America/New_York"); 
echo "New-York:".strtotime("midnight");
echo "<br><br>";
date_default_timezone_set("UTC"); 
echo "UTC:".strtotime("midnight");
echo "<br><br>";
?>

Expected result:
----------------
Kiev:1394781415

New-York:1394781415

UTC:1394781415
==========================
Kiev:1394748000

New-York:1394769600

UTC:1394755200


Actual result:
--------------
result:
Kiev:1394781415

New-York:1394781415

UTC:1394781415
==========================
Kiev:1394755200

New-York:1394755200

UTC:1394755200


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-14 07:34 UTC] a dot dyudyun at gmail dot com
About results !!! 
=================

Actual result:
----------------
Kiev:1394781415

New-York:1394781415

UTC:1394781415
==========================
Kiev:1394748000

New-York:1394769600

UTC:1394755200


Expected result:
--------------

Kiev:1394781415

New-York:1394781415

UTC:1394781415
==========================
Kiev:1394755200

New-York:1394755200

UTC:1394755200
 [2014-03-14 07:45 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-03-14 07:45 UTC] requinix@php.net
I take that to mean the Expected and Actual results in the report were backwards?

Not a bug. "Now" is the same everywhere in the world, thus the same timestamp, but "midnight" most certainly is not.
 [2014-03-14 08:44 UTC] a dot dyudyun at gmail dot com
So strtotime it's function that work with local time zones or with UTC? or with both? It's problem for me because strtotime("now") and strtotime("now GMT") it's have some diff
 [2014-03-14 08:50 UTC] a dot dyudyun at gmail dot com
How i can know when i write some word-params to strtotime() whet it will be UTC and whet it use local time. For example strtotime("next month -1 day")?
 [2014-03-14 08:57 UTC] a dot dyudyun at gmail dot com
<?php
date_default_timezone_set("Europe/Kiev");
echo "Kiev: ".strtotime("now") . " " . strtotime("now UTC");
echo "<br><br>"; 

date_default_timezone_set("America/New_York"); 
echo "New-York: ".strtotime("now") . " " . strtotime("now UTC");
echo "<br><br>";
date_default_timezone_set("UTC"); 
echo "UTC: ".strtotime("now") . " " . strtotime("now UTC");
echo "<br>==========================<br>";

date_default_timezone_set("Europe/Kiev");
echo "Kiev: ".strtotime("midnight") . " " . strtotime("midnight UTC");
echo "<br><br>";

date_default_timezone_set("America/New_York"); 
echo "New-York: ".strtotime("midnight") . " " . strtotime("midnight UTC");
echo "<br><br>";
date_default_timezone_set("UTC"); 
echo "UTC: ". strtotime("midnight") . " " . strtotime("midnight UTC");
echo "<br><br>";
?>

Result:
Kiev: 1394787250 1394794450

New-York: 1394787250 1394772850

UTC: 1394787250 1394787250
==========================
Kiev: 1394748000 1394755200

New-York: 1394769600 1394755200

UTC: 1394755200 1394755200

======================

Comments: Why "now" and  "now UTC" has different values? its a bug!
 [2014-03-14 09:08 UTC] requinix@php.net
It will use whatever timezone you provide, or the default if there wasn't one. The question is whether the timezone matters for the string you provide.
"now" is now, like I said. Timezone is irrelevant. "now UTC" will be the current time in your timezone treated as if it were instead a UTC time. "next month -1 day" will be the current date and time, in the current timezone, in one day less than a month from now.

There is documentation specifically dedicated to this question.
http://www.php.net/manual/en/datetime.formats.php
If that doesn't answer your question about a format, simply try it and see what happens.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 18:01:30 2024 UTC