: This article mainly introduces that the GMT + 8 string of the PHP conversion database is the user's local time zone. if you are interested in the PHP Tutorial, refer to it.
- Write user time zone into cookie
- Php reads and processes user time zones
When you open your browser, you can use js to get the time zone and write the cookie.GithubAn open-source library on
Https ://Github. Com/js-cookie
The specific code is as follows:
// Write the time zone to Cookie. the unit is minute. However, note that Offset here is a negative value, indicating the difference between local time and GMT. var d = new Date (); Cookies. set ('localzone ', d. getTimezoneOffset ());
On the PHP server, if the time value stored in the database field is a timestamp, it is much easier to handle. However, note that, if the default value of your server is the timestamp of GMT + 8, instead of the timestamp of GMT, you need to handle it. the code is as follows (here I use ThinkPHP Framework)
$ Tmp = strtotime ($ strTime); // Here, convert the string in Y-m-d H: I format to the timestamp $ tmp = $ tmp-(8*3600 ); // the string stored on the server is GMT + 8, so here I subtract 8 hours in milliseconds, that is, get the GMT timestamp $ timeZone =-cookie ('localzone '); // because of the difference, you need to add, therefore, convert it to a positive value $ tmp = $ tmp + ($ timeZone * 60 ); // add the time zone where the browser is located $ logInfo [$ I] ['Access _ time'] = date ('Y-m-d H: I ', $ tmp ); // format the timestamp Y-m-d H: I
The above introduces the string of GMT + 8 in the PHP conversion database for the user's local time zone, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.