Hi,
Apologies if this has moved on, I've not read all my mail from the last
day and a half.
On Mon, 21 Nov 2011, Tedd Sperling wrote:
Let's consider this -- you are in a different time zone than me, right?
You said UTC and mine is America New York. As such you claim is that
your strtotime() function will return a different result for you as
compared to me because of the time zone differences, right?
Only some of the time. It depends on the input.
If so, then tell me why I can take both sites (your and mine) and click
the Submit buttons at the same time and the forms will report back the
exact same number of elapsed seconds. Try it (you got to be quick):
The timezone affects two things, the input and the output. If your input
is absolute and not timezone dependent, both scripts will output the same
seconds calculation. But if it is affected by timezone, then the seconds
count will be different.
Here's an example from a previous message. The string "1 January 1970
00:00:00" is timezone dependent, as it is midnight according to the
particular timezone.
Output from your copy:
String Given: 1 January 1970 00:00:00
Seconds Computed from String: 18000
Output from my copy:
String Given: 1 January 1970 00:00:00
Seconds Computed from String: 0
This is because the number of seconds (aka the Unix Timestamp) is *not*
affected by timezones - it's the number of seconds since 1 January 1970
00:00:00 UTC. This is why it's 0 on my server and 18000 on yours, as
midnight was 5 hours later in New York.
But if you enter a string like "now", you'll get the current time with the
same timestamp from both scripts.
String Given: now
Seconds Computed from String: 1322033486
Here's where the output side comes in. The various date display
functions will output according to the selected timezone, or the system
default if none is selected. So this will display differently on your
server and on mine.
Lets use the value of 'now' above to demonstrate:
$ php -r 'date_default_timezone_set ("America/New_York"); echo date ("r",
1322033486);'
Wed, 23 Nov 2011 02:31:26 -0500
php -r 'date_default_timezone_set ("UTC"); echo date ("r", 1322033486);'
Wed, 23 Nov 2011 07:31:26 +0000
Same input, different output.
Now if you combine these two factors, it explains all the results you see.
If you use strings like "today" or "1 January 1970 00:00:00", the scripts
will print the same date (and time if you asked it to), but they aren't
actually the same, as one is 5 hours behind the other. But if you use an
absolute time like "now" or "1 January 1970 00:00:00 +0000" (which
specifies the timezone), the scripts will print different times based on
the timezone.
Now, to the point under debate. Since values like 0 and null are absolute
rather than relative, the output will vary depending on which timezone is
in use.
$ php -r 'date_default_timezone_set ("UTC"); echo date ("r", null);'
Thu, 01 Jan 1970 00:00:00 +0000
$ php -r 'date_default_timezone_set ("America/New_York"); echo date ("r",
null);'
Wed, 31 Dec 1969 19:00:00 -0500
Geoff.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php