Jump to content
xisto Community
Chesso

Php And Time Zones.....

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

 

$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 1154530597 then the local timestamp would be 1154548597 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 1154530597 + -18000 would be 1154512597.

 

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:

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! :unsure:

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 Xisto server yet.

 

Well, I hope this helps. :D

 

vujsa

Share this post


Link to post
Share on other sites

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.

Do you mean date_default_timezone_set() function??? well, if it is, you can't use this function with the Asta's server because this function only works with PHP 5+ and as you know the Asta's server works with PHP 4.4.2. Now, the parameter that this function use is a timezone identifier and for your case it is Australia/Sydney, you can find a complete list of timezone identifiers in the appendix H of the php manual.

Best regards,

Share this post


Link to post
Share on other sites

So they do list the timezones somewhere? That's good to hear, I even googled it like crazy and couldn't find anything usefull.Yeah I also found out about that function only working for PHP5+.

Share this post


Link to post
Share on other sites

Here is the site I use: http://www.worldtimezone.com/

 

Good Luck.

 

vujsa

 

Nice and helpful site, but the only thing i dont like about it is that the name of my country Perú does not appears :D

 

Best regards,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.