Being blond, confusion is my normal state, but time zones are threatening to ruin what's left of my mental health.
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?
If I read the PHP manual correctly, the strtotime() function will create a GMT time. Is that correct?
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?
Nancy
Hmm... Well actually the strtotime function returns the current time in the "default" timezone by default. The default timezone is not necessarily your php.ini file's timezone as it can be overridden with a call to the php function date_timezone_set. Everyone have a headache yet?
The best way to determine which timezone is affected by strtotime() is to stick in a command like (assuming you have the devel module enabled): dsm(date_default_timezone_get()); On my drupal installation this does not return GMT number. So what you want to do if you want GMT time is to append "GMT" to the time.
Check out the following code snippet: $output = '<pre>'; $output .= date_default_timezone_get() . "\n"; $output .= strtotime('January 1 1970 00:00:0'). "\n"; $output .= strtotime('January 1 1970 GMT') . "\n";
$output .= '</pre>';
On my box this returns.
America/Los_Angeles
28800
0
Hope that helps.
________________________________ From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Ms. Nancy Wichmann Sent: Thursday, February 28, 2013 7:55 AM To: support drupal Subject: [support] Time Zones
Being blond, confusion is my normal state, but time zones are threatening to ruin what's left of my mental health.
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?
If I read the PHP manual correctly, the strtotime() function will create a GMT time. Is that correct?
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?
Nancy
As I thought about this I realized my interpretation of the data was wrong.
28800 is the time it was GMT when it was January 1 1970 00 in Los Angeles. So in some senses maybe that's the time that you want, and your solution is correct. If you tack on the users time zone you will get the number of seconds it was away from 'January 1 1970 GMT'.
I'd go ahead and experiment with this January 1 1970 date and see if your solution works for the user entered time zones you provide.
________________________________ From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Metzler, David Sent: Thursday, February 28, 2013 8:38 AM To: 'support@drupal.org'; 'Ms. Nancy Wichmann' Subject: Re: [support] Time Zones
Hmm... Well actually the strtotime function returns the current time in the "default" timezone by default. The default timezone is not necessarily your php.ini file's timezone as it can be overridden with a call to the php function date_timezone_set. Everyone have a headache yet?
The best way to determine which timezone is affected by strtotime() is to stick in a command like (assuming you have the devel module enabled): dsm(date_default_timezone_get()); On my drupal installation this does not return GMT number. So what you want to do if you want GMT time is to append "GMT" to the time.
Check out the following code snippet: $output = '<pre>'; $output .= date_default_timezone_get() . "\n"; $output .= strtotime('January 1 1970 00:00:0'). "\n"; $output .= strtotime('January 1 1970 GMT') . "\n";
$output .= '</pre>';
On my box this returns.
America/Los_Angeles
28800
0
Hope that helps.
________________________________ From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Ms. Nancy Wichmann Sent: Thursday, February 28, 2013 7:55 AM To: support drupal Subject: [support] Time Zones
Being blond, confusion is my normal state, but time zones are threatening to ruin what's left of my mental health.
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?
If I read the PHP manual correctly, the strtotime() function will create a GMT time. Is that correct?
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?
Nancy
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, that's not correct at all. Most servers will be set to their own local time zone AFAIK.
If I read the PHP manual correctly, the strtotime() function will create a GMT time. Is that correct?
You can always get real GMT time with gmmktime http://php.net/manual/en/function.gmmktime.php Compare that to mktime to confirm.
Fred
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,