tags:

views:

300

answers:

4

Our server is set to GMT time so the hour does not keep jumping around in spring and autumn. However, during summer time, it is annoying that all the times are displayed an hour out.

How do I get and display the time, taking into account the local timezone in PHP (especially when the server thinks the local timezone is GMT).

or, How do I know if an area is using "summer time" at the moment?

or, How do I display a GMT time stamp or a different timezone?

A: 

get the date/time and first check to see if the month (split on dashes if its a DATETIME field) is a 'summer month', or a month that will cause the time to be an hour out.

If so, convert it to a unix timestamp. Then, add (or minus, whichever way it is out) 60 * 60 (60 mins) to the timestamp and convert into a human readable format.

Problem solved!

Evernoob
summer time does not switch on and off on month boundaries. You may know "summer time", as "daylight saving time".
rikh
There are built-in functions for this! Hacking your own Daylight Saving Time (and this is a nasty hack) is how things get broken down the road.
Sidnicious
Problem not solved. Problem deferred.
GZipp
A: 

You can use the date function to offset GMT

Ryan Kearney
Can you? How do you do this? You can use it to find out if daylight saving time is on, or what the timezone is, but I can't see how to adjust the timezone using this function...
rikh
+2  A: 

You could add this line in PHP:

putenv("TZ=US/Eastern");

And every subsequent call to time()/date() will give you the time in your time zone.

List of time zones

This code will display the current time in the Eastern time zone (US):

putenv("TZ=US/Eastern");
date("h:i:s")
jimyi
+2  A: 

Actually, I think I may have found the answer I need...

date_default_timezone_set()
// Sets the default timezone used by all date/time functions in a script

The PHP manual entry is here:- http://us2.php.net/manual/en/function.date-default-timezone-set.php

rikh