Daylight Saving Time...Simple?

I have searched everywhere I know to look (yes…I searched google), however, I have thus far been unable to find a solution to my problem. I would like users to be able to log into my site and set the timezone to whatever they want it to be. Well, that was easy. Now I would like the site to display the correct time. That is not so easy, as it turns out. I don’t know how to go about accounting for DST in every timezone in the world. I have found functions in PHP to translate the time into a specific timezone, however, the functions would like for me to tell them whether DST is in effect. I HAVE GOT TO BE OVERLOOKING SOMETHING!! Really, it can’t be this hard. The only solution I have come up with is to write a script to manually account for each timezone’s DST rules (which apparently changes from region to region within each timezone). If anyone can help me break this wall of stupidity (it has to be something I am overlooking, right?), please do so. You can even let me know how stupid I am.

u should use unixtimestamps internaly (vars, MySQL-fields a.s.o.) cause they are unice its always the time since January 1 1970 00:00:00 GMT.

then to display/convert input u may use all date/time functions (date(), strtotime() a.s.o.) as long as u have set the timezone first, with date_default_timezone_set(), these are timezones like “Europe/Lisbon” so thay are DST save. to find out whether DTS is in affect u may still use date(‘I’).

this will only work with php 5 >= 5.1.0, but that should be no prob

What I did was write a little function (i.e. getPersonalTime(offset, dst)) and have it calculate the time manually from the server timestamp.

Say you have a server which is set to GMT-5 (Miami for example). The following would apply:

$servertime = time(); // fetch timestamp from machine - GMT-5
$GMTtime = $servertime + (5 * 3600); // Calculate GMT time

$usertime = $GMTtime + $offset; // Calculate user’s timezone time

if ($dst) {
$usertime += 3600; // If DST is true, add one hour to the user time.

This works if you know what timezone your server machine is set to (which is usually quite easy to figure out).

Sponsor our Newsletter | Privacy Policy | Terms of Service