mysql - understanding results of global.time_zone -


I am considering ways to change the time zone of my database because my user base is UK-based, but my domain is U .s. Based I've searched several options including PHP, Peer Time Class, and MySQL functions. MySQL's Time_Zone parameter is included in the simplest of me (mainly because it starts and ends with MySQL)

In preparing to do this, I only call MySQL @@ global.time_zone (As I think it is better before it starts playing with it) It creates the full weight of those criteria which I did not expect, and fails to mention the MySQL site () - it is clearly an array, many identifiers like this log-in protocol etc. Returns the parameter, but I can not see any clear parameters Return to anything with timezone

Do you have any experience with this? Can you give advice? Many thanks in advance.

There are 2 keys to dealing with timezones:

  1. Store all your dates / time in the same timezone (any time zone may be there, but using UTC makes things easy.)

  2. Where in the application, the date / time will be converted from the time zone to the user's display timezone from time to time. This database can be done in the relics layer, app code or page template (originally any part of the MVC stack). The important thing is that be consistent.

Also remember that php has its own timezone setting independent of mysql if you are running php> 5.1, then you can use datetimeset_default_time () to run PHP on runtime Timezone can change.

If you decide to do a timezone conversion while retrieving / collecting information in the database, then the MySQL convert_type () function will become your new best friend.

For me it has been easy to adapt the timezone as part of this page template. The date / time gets accumulated in the database in the UTC timezone, and all application logic is also in UTC. While outputting a date in HTML, I use an envelope function for the date of php to output the date in user's timezone:

  function getTimezoneOffset ($ time) , $ Timezone) {$ t = new date time (date ('YMD HH: I: S', $ time)); $ Tz = new datetime zone ($ timezone); $ T & gt; SetTimeZone ($ TZ); Return $ t- & gt; GetOffset (); } Function myDate ($ timezone, $ format, $ timestamp = false) {if (! $ Timestamp) $ timestamp = time (); Return Date ($ format, $ timestamp + gatemezen offset ($ timestamp, $ timezone)); }  

Similarly, while taking input from the user through the form, do the timezone conversion first so that your application can work with UTC date / time.

Another option is to use PostgreSQL - Unlike MySQL, time zones are supported for dataatmons.


Comments