QUOTE(Chesso @ Jul 31 2006, 08:35 PM)

As of right now when a user replys on my forums I store the date/time in the thread table/row for display so users know when the last reply was made.
This looked ok for me on my computer for local testing using WAMP5 because of course my computer is set to my timezone, but I reliased after I had updated my site last night with the new feature and checked the site dismorning that it is using the timezone for Asta's server.
Iv'e done some searching and found this default_timezone_set() function for PHP but it doesn't tell me how to find what I should give as the paramater for my particular timezone (I'm in Sydney so GMT+10, EST, I think).
Anyone know how to use this function?
P.S. I use the date() function and just store it as a string in the mysql database.
Well, I think the best way to do what you want is to require the user to specify their timezone. Which will set the offset from UTC. If you save your dates as timestamps which is probably best since it will offer you more options in the future then you can simply add or sbtract the offset to get the users local time.
CODE
$user_tz = 5;
$user_offset = $user_tz * 3600; // Number of hours X number of minutes X number of seconds
$timestamp = time();
$local_timestamp = $timestamp + $user_offset;
In this case, if the timestamp was 11545
30597 then the local timestamp would be 11545
48597 of 18000 seconds ahead.
Then use your date function as normal but instead of leaving the timestamp condition blank, specify it as $local_timestamp.
If the users timezone had been -5, the formula would still be the same since -5 * 3600 would be -18000. Then 11545
30597 + -18000 would be 11545
12597.
Now, you do have several options for the storing and retrieving of the users time offset.
You can either save the user's offset in the database as hours or seconds. If you save it a seconds then you only need to calculate it one time when you first save it or you can save it as hours and recalclate the number of seconds every time the user's offset is required.
When it comes time to retireve the offset, you can either request it from the database for each page and use it from there or you can request it once when a session is started and save it in the session variable like so:
CODE
session_start();
if(!isset($_SESSION['user_offset'])){
$_SESSION['user_offset'] = 18000; // You would actually get this data from the database.
}
There is one more thing to consider, Daylight Savings Time!
During the summersome countries change their time to have more usable daylight in the evening instead of the early morning. In the northern hemisphere, this is from April 1st to October 1st and I guess it is the opposite in the southern hemisphere. As a result, during DST, you will need to subtract one hour (3600 seconds) from the user's offset if and only if they infact use the DST system where they live. I personally don't understand why anyone would change their time twice a year. It gets dark here (Indiana, US) right now (August 2nd) at about 9:30 PM. Really anoying cause I forget to eat until like 8:30 or 9:00 PM now.
You'll need an option for your user to select if they will be using DST in the summer.
I'm sorry I didn't discuss the date_default_timezone_set() function since it is new to PHP5 and we aren't using PHP5 on the AstaHost server yet.
Well, I hope this helps.
vujsa
Comment/Reply (w/o sign-up)