[support] Time Zones

Earnie Boyd earnie at users.sourceforge.net
Thu Feb 28 18:43:06 UTC 2013


On Thu, Feb 28, 2013 at 10:55 AM, Ms. Nancy Wichmann wrote:
> Being blond, confusion is my normal state, but time zones are threatening to
> ruin what's left of my mental health.
>

Timezones are a PITA that we could all do without.  However, a
timezone is a reference to a display of a point in time that is
relevant only to the user.  I.E. regardless of if it is 7:00 -05:00 or
if it is 12:00 00:00 it is all the same point in time.  Note that the
-05:00 could be Eastern Standard Time (as we call it in the US) or it
could be Central Daylight Time when the time switches in March.  All
that Daylight Savings Time does is move the reference of time ahead by
an hour.

> In D7, we set the site's default time zone (America/New_York for me). Since
> it then displays the correct time, I have to assume that the server is
> running on GMT. Is that correct?
>

No, it could even be something different entirely; usually it will be
the timezone for the location in which the server resides.  The
mathematics for the display of the point in time has to use the 00:00
to base the calculation to display in to you in your timezone
reference for that point in time.

> If I read the PHP manual correctly, the strtotime() function will create a
> GMT time. Is that correct?
>

It can but it depends on the string you give it and rather than GMT I
would use UTC instead.  So if you want to know the time of day someone
gives you, you need to convert the time given from one to another
format, you can use strtotime() to get the timestamp integer and then
use strftime to display that in your timezone.

<?php
define (TIMEMASK, '%r %Z');
$timestamp=strtotime("05:00 EST");
$mytime=strftime(TIMEMASK, $mytime);
echo $mytime;
?>

Note that the timezone used by strftime is the one set as the default
for the PHP session.  You can change that using
date_default_timezone_set() if it is not to your liking.

> So if I ask the user to tell me their timezone when they enter a time, I can
> stick that on the end of the string that I pass to strtotime() and get a GMT
> timestamp?
>

There is no such thing as a GMT timestamp; the timestamp is a numeric
integer of a point in time and GMT is the designated string
representation for the numeric integer.  So the timestamp is a
reference to the point in time and that point in time can be
represented as any timezone.

HTH,
-- 
Earnie
-- https://sites.google.com/site/earnieboyd


More information about the support mailing list