Hobbyist_PHPer Posted September 15, 2012 Share Posted September 15, 2012 Hello everyone... So if you're creating an application that will be accessed in multiple timezones, what is the best way of accomplishing that? The current system I have in place seems very clunky and quite a pain in the butt... Here's how I currently have it set up... The entire application is set to GMT, date_default_timezone_set('UTC'); in the Config.php file I store the user's timezone difference in the database in their preferences, so that when they log in, their time difference is then stored in a session variable, as either plus or minus a certain amount of hours Then every time the user inserts or retrieves a record to/from the database, it adds or subtracts the user's time difference prior to insertion / retrieval Thank you in advance if you have a better method... Quote Link to comment https://forums.phpfreaks.com/topic/268412-working-with-multiple-timezones/ Share on other sites More sharing options...
Christian F. Posted September 15, 2012 Share Posted September 15, 2012 What you have there is the best way to deal with it. Quote Link to comment https://forums.phpfreaks.com/topic/268412-working-with-multiple-timezones/#findComment-1378228 Share on other sites More sharing options...
gizmola Posted September 15, 2012 Share Posted September 15, 2012 In terms of PHP, the DateTime class has timezone arithmetic built into it. Your approach is the same, only I would store the timezone string for each user, and use that to convert variables using the timezone class to do so. Quote Link to comment https://forums.phpfreaks.com/topic/268412-working-with-multiple-timezones/#findComment-1378231 Share on other sites More sharing options...
Hobbyist_PHPer Posted September 15, 2012 Author Share Posted September 15, 2012 Ok, thanks everyone for your help... Much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/268412-working-with-multiple-timezones/#findComment-1378232 Share on other sites More sharing options...
ignace Posted September 15, 2012 Share Posted September 15, 2012 Like gizmola already mentioned I would just store their timezone and simply set date_default_timezone_set() to their timezone instead of simply UTC and all your dates will be automatically adjusted. Or use DateTime with a DateTimeZone object but that seems more work IMO. When working with dates I use github:Carbon. Quote Link to comment https://forums.phpfreaks.com/topic/268412-working-with-multiple-timezones/#findComment-1378236 Share on other sites More sharing options...
gizmola Posted September 15, 2012 Share Posted September 15, 2012 Ditto on Carbon, I should have mentioned it. A lot of really nice stuff in there. Quote Link to comment https://forums.phpfreaks.com/topic/268412-working-with-multiple-timezones/#findComment-1378238 Share on other sites More sharing options...
Hobbyist_PHPer Posted September 15, 2012 Author Share Posted September 15, 2012 Thanks again guys Quote Link to comment https://forums.phpfreaks.com/topic/268412-working-with-multiple-timezones/#findComment-1378246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.