- Write User time zone to cookie
- PHP reads the user time zone and processes
The moment the user opens the browser, uses JS to get the time zone and write the cookie, which can be manipulated using an open source library on GitHub .
https://GitHub. Com/js-cookie/js-cookie
The specific code is as follows
Write the time zone to a cookie in minutes, but note that offset here is a negative number, indicating the difference between local time and GMT var d = new Date ();
On the PHP server side, if the time value stored in the database field is timestamp, then it is good to handle a lot, but it is important to note that if your server defaults to the timestamp of the gmt+8 time zone instead of the GMT timestamp, then you need to process the code as follows (here I use think PHP Framework )
$tmp = Strtotime ($strTime); This converts a string of y-m-d h:i format into a timestamp $tmp = $tmp-(8 * 3600);//The string stored by the server is gmt+8, so here I subtract 8 hours of milliseconds, which is the time stamp of GMT $timeZone = -cookie (' Localzone '); Because of the difference, need to add, so turn into a positive $tmp = $tmp + ($timeZone * 60);//plus the time zone of the browser's location $logInfo [$i] [' access_time '] = Date (' y-m-d h:i ', $TMP); Format timestamp as y-m-d h:i
The above describes the PHP conversion database gmt+8 string for the user's local time zone, including the contents of the content, I hope to be interested in PHP tutorial friends helpful.