The GMT + 8 string of the PHP conversion database is the user's local time zone.

Source: Internet
Author: User
Tags time zones
: 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.
  1. Write user time zone into cookie
  2. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.