Jump to content

Working with multiple timezones


Hobbyist_PHPer

Recommended Posts

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.