Coding for different Time Zones

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Coding for different Time Zones

Post by Ambush Commander »

I'm finishing up a personal command line script project I started a few days ago to build an automatic comprehensive backup system for my computer (after all, hard drives do fail).

I was wondering, though, is there any point in adapting the system so it works in different time zones? How does one go about doing that, especially my bigger project I'm going to be moving into MySQL and I don't have much knowledge about how they handle time in different time zones and etc. Anyone have any good primer docs on this? Any suggestions?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's pretty simple to just use gmt, as the times are most often in reference to the server anyways. If you want to base things off the user logged in, then using their machine's time (via Javascript) can be done, however, the server's time is often more trustable.. so offering a personal timezone setting can help you offset the server's (GMT) time to theirs..
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

A server, however, would set the time according to where it's located?

And how would it work with timestamps?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I write my code to always use GMT, as that's fairly simple for the server to determine, and if the server is moved, the code will still work as is. The server itself will have a "local" time setting which it uses to offset the time it finds when the server's time needs to be referenced (for whatever reason).. the user has a seperate timezone setting whereby all times are adjusted to when doing visual calculations..
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

You could combine the javascript method with the 'setting method', allow the user to set their time zone but use javascript to send the current time as a user signs up, use the current time that is sent with javascript as their default.
Post Reply