I store time in UTC timezone in the MySQL DATETIME field. I want to change all of these (when using them in PHP) the user has the time zone I know that I can do it with php DateTime :: setTimezone, but each of them has to do this each.
Is there a global way to tell php that all datasets from mysql are UTC and are converted to user timezone?
When you store them in a database, the table columns are stored in a form such as a Unix timestamp These are all UTC, then simply apply the user you want to specify the offset.
Here's an interesting thing that you are likely to help with it.
You can easily access data from queries to the right while comparing Int.
EDIT: If you are certain that every time you use them, then you want to change all the datasets from the database, just write a simple task, which is received from time to time. And the correct offset adds the user, then just call that function every time you use a datetime from the database. Like the code below:
& lt ;? Php // Assume that $ _SESSION ['UserOffset'] is accumulating user's timezones like // $ _SESSION ['UserOffset'] = new datetime zone ("Europe / Prague"); Function convert_time_john ($ timeframedatabase_time) {$ userTime = new date time ($ timeformdatesbase, new datetimezone ('UTC')); $ UserTime- & gt; Settimezone (new date timezone ($ _ session ['user offset']); Return $ userTime-> Format ('Y-M-DH: I: S'); // or $ userTime return; // if you specify datetime Want to return the object}? & Gt;
Comments
Post a Comment