View Full Version : Resolved strtotime() problem
james438
09-15-2010, 09:17 PM
hi,
I have the following line:
echo strtotime("10 September 2000"), "\n";
If I echo this on one page I get one time and if I echo this on another page I get another time that is an hour ahead of the the other page. I know that this is due to a WordPress include file, but am not sure how they are manipulating the time variable as $SERVER['REQUEST_TIME'] and time() values are unchanged.
echo strtotime("10 September 2000"), "\n"; takes place after the include.
any ideas?
fileserverdirect
09-16-2010, 02:00 AM
Are you sure it is an hour? the milliseconds can be deceiving if you don't convert them back right. It could just be the difference from when you did one test and when you did the second.
james438
09-16-2010, 02:50 AM
if I compare the time in seconds from one page to the next it is off 3600 seconds, which is why I add 3600 seconds to equal the two pages out.
echo "<br>$_SERVER[REQUEST_TIME]<br>";
$_SERVER['REQUEST_TIME']=time()+3600;
echo "$_SERVER[REQUEST_TIME]<br>";
print time();
$starttime = strtotime("$qdate");
echo"<br>$starttime";echo "<br>$qdate";
on test1.php where the WordPress include is used I get the following:
1284605171
1284608772
1284605172
1282953600
28 August 2010
on test2.php I get:
1284605149
1284608749
1284605149
1282975200
28 August 2010
I am not sure how to reproduce this when the WordPress include is not present.
Clarify: on test2.php, Wordpress is not involved?
I don't use Wordpress, but I based on other CMSs, I would suspect some sort of timezone function. test1 would be using the Wordpress-configured timezone, and test2 would be using your server's default timezone.
...?
james438
09-16-2010, 07:34 AM
On test2.php WordPress is not involved.
I agree that WordPress is manipulating the timezone, but I seem unable to replicate this in order to fix the problem. Actually, I plan on creating a better workaround if I can figure out what they are doing.
P.S. Congrats on making it to Elite Coder :)
P.S. Congrats on making it to Elite Coder :)
ha! I didn't even know what you were talking about :p
had to look around
maybe a WP forum would be a better place to find a solution?
james438
09-16-2010, 05:08 PM
Maybe, but I think that this involves the strtotime() function. In the examples listed above I manipulated the $_SERVER['REQUEST_TIME'] and printed the time() values as well as the unmanipulated $_SERVER['REQUEST_TIME'] and the $qdate value and as you can see they are unchanged from page 1 to page 2 just as it should be, but strtotime() seems to think that the current UNIX timestamp is different depending on the page. I am using php 5.2.8. This means to me that somehow the UNIX timestamp is being manipulated, but not by any method I am familiar with.
If I find the answer I'll try to post something here.
echo date_default_timezone_get() . ' => ' . date('e') . ' => ' . date('T');
Will echo
UTC => UTC => UTC on a WordPress included page and
America/Denver => America/Denver => MDT on a non WordPress page.
EDIT: Solved it.
date_default_timezone_set('America/Los_Angeles');
will set the timezone to the correct timezone. The UTC value is pulled from many available sources and when none is available or the value is not formatted correctly you will get a UTC printed out as demonstrated above. Now to set it to Iowa/Illinois time where I live. I am not sure what happens with daylight savings time though, but I'll worry about that then, if it ever comes up.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.