I’ve been receiving the usual PHP warnings for using strtotime without setting a default time zone:
PHP Warning: date_default_timezone_get(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Chicago’ for ‘CST/-6.0/no DST’ instead
I read up a lot on what needs to be done, and basically there doesn’t seem to be a way around setting a default timezone (either in php.ini as date.timezone = “America/Chicago”, or in PHP using date_default_timezone_set(‘CST6CDT’) or similar).
My problem is that we have a moving server that will frequently be in different time zones for demos, so I can’t just set a fixed timezone and have everything work wherever we go…
Or can I? There’s of course also the possibility that I’m completely misunderstanding the whole timezone concept 😉 Frankly, it’s just confusing me more the more I read about … I also don’t know for sure how the server’s system time is affected by plugging it into a network in a different time zone – there’s just too much I don’t know or understand yet (sorry…).
Main reason I want these error messages to stop is that I have to sift through the error logs a lot since this is also my development server, and having to filter all these lines out is just a major pain…
On top of all of that, the application on the server not only uses local times, but it also synchronizes some data with our static server, so I am painfully aware that I’ll have to adjust a lot of main server code as well, and for that I can easily force our actual time zone or UTC.
So what’s the best option here?
Should I simply hard code UTC in as default time zone, then create a setting in my database and a user interface that we can use to switch time zones and update ALL my code to use all of that, or is there a better and simpler way?
Or should I ignore the whole issue and add @ to every strtotime I use? (bracing myself for a small riot…) 😉
Looking forward to any suggestion…
Thanks!
Andy Jones is correct. Your best bet is to baseline your server completely. What I mean by this is to set all encodings (bash, mysql) to UTF-8 and timezones to UTC. If you do this from the outset, you will save yourself a lot of headache down the road.
With respect to the question you asked, if you store all timestamps in your database as UTC, then you only need to convert based on the end user’s timezone. This avoids having to determine if a timezone stored in the database was PST or EST then convert to user’s timezone. Plus it allows you to move servers between timezones. For example if you are using VPS across multiple timezones, each of which feeds into the same database, you are ensured that all timezone entries are consistent.