What is the best way to set the time zone? I have a website with user accounts and I want to users to have the ability to select their timezone.
I found this function: http://au2.php.net/date_default_timezone_set ans I also found putenv("TZ=US/Eastern"); which looks a bit dodgey to me...
What is the normal practice for changing time zone for user accounts? And what happens when the user changes their timezone? Does that mess up the dates or will it switch over? I am currently storing dates as DATETIME in the database.
Thanks for your help!
Best way to set the timezone
Moderator: General Moderators
Re: Best way to set the timezone
It's best to store your timestamps as GMT - that way they'll always be the same. You can then modify those dates when displaying to the user, by using their timezone choice. Using a built in PHP function to set the timezone is probably better than setting an environment variable.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: Best way to set the timezone
Use the date_default_timezone_set() function, not putenv().
Re: Best way to set the timezone
How would I store the date as GMT? So will the date_default_timezone_set() then convert any GMT dates pulled from the database to the correct time zones time?
Re: Best way to set the timezone
How do you currently know what timezone your dates are in?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.