<small id='B2vE5'></small><noframes id='B2vE5'>

  • <tfoot id='B2vE5'></tfoot>

      <i id='B2vE5'><tr id='B2vE5'><dt id='B2vE5'><q id='B2vE5'><span id='B2vE5'><b id='B2vE5'><form id='B2vE5'><ins id='B2vE5'></ins><ul id='B2vE5'></ul><sub id='B2vE5'></sub></form><legend id='B2vE5'></legend><bdo id='B2vE5'><pre id='B2vE5'><center id='B2vE5'></center></pre></bdo></b><th id='B2vE5'></th></span></q></dt></tr></i><div id='B2vE5'><tfoot id='B2vE5'></tfoot><dl id='B2vE5'><fieldset id='B2vE5'></fieldset></dl></div>
      <legend id='B2vE5'><style id='B2vE5'><dir id='B2vE5'><q id='B2vE5'></q></dir></style></legend>
      • <bdo id='B2vE5'></bdo><ul id='B2vE5'></ul>
      1. 处理不同时区的PHP服务器和MySQL服务器

        时间:2024-08-14
        <i id='Sybij'><tr id='Sybij'><dt id='Sybij'><q id='Sybij'><span id='Sybij'><b id='Sybij'><form id='Sybij'><ins id='Sybij'></ins><ul id='Sybij'></ul><sub id='Sybij'></sub></form><legend id='Sybij'></legend><bdo id='Sybij'><pre id='Sybij'><center id='Sybij'></center></pre></bdo></b><th id='Sybij'></th></span></q></dt></tr></i><div id='Sybij'><tfoot id='Sybij'></tfoot><dl id='Sybij'><fieldset id='Sybij'></fieldset></dl></div>
              <bdo id='Sybij'></bdo><ul id='Sybij'></ul>
            • <legend id='Sybij'><style id='Sybij'><dir id='Sybij'><q id='Sybij'></q></dir></style></legend>

                <tfoot id='Sybij'></tfoot>

                    <tbody id='Sybij'></tbody>

                • <small id='Sybij'></small><noframes id='Sybij'>

                  本文介绍了处理不同时区的PHP服务器和MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  对于我们这些使用标准共享托管包(例如 GoDaddy 或 Network Solutions)的人,当您的托管服务器 (PHP) 和 MySQL 服务器位于不同时区时,您如何处理日期时间转换?

                  For those of us who use standard shared hosting packages, such as GoDaddy or Network Solutions, how do you handle datetime conversions when your hosting server (PHP) and MySQL server are in different time zones?

                  另外,对于确定您网站的访问者所在的时区和适当地操作日期时间变量,是否有人提供了一些最佳实践建议?

                  Also, does anybody have some best practice advice for determining what time zone a visitor to your site is in and manipulating a datetime variable appropriately?

                  推荐答案

                  从 PHP 5.1.0 开始,您可以使用 date_default_timezone_set() 函数设置脚本中所有日期/时间函数使用的默认时区.

                  As of PHP 5.1.0 you can use date_default_timezone_set() function to set the default timezone used by all date/time functions in a script.

                  对于 MySql(引自 MySQL 服务器时区支持 页)

                  For MySql (quoted from MySQL Server Time Zone Support page)

                  在 MySQL 4.1.3 之前,服务器只在启动时设置的系统时区运行.从 MySQL 4.1.3 开始,服务器维护了几个时区设置,其中一些可以在运行时修改.

                  Before MySQL 4.1.3, the server operates only in the system time zone set at startup. Beginning with MySQL 4.1.3, the server maintains several time zone settings, some of which can be modified at runtime.

                  您感兴趣的是时区的每个连接设置,您将在脚本开头使用它

                  Of interest to you is per-connection setting of the time zones, which you would use at the beginning of your scripts

                  SET timezone = 'Europe/London';
                  

                  至于检测客户端时区设置,您可以使用一些 JavaScript 来获取该信息并将其保存到 cookie,并在后续页面读取时使用它来计算正确的时区.

                  As for detecting the client timezone setting, you could use a bit of JavaScript to get and save that information to a cookie, and use it on subsequent page reads, to calculate the proper timezone.

                  //Returns the offset (time difference) between Greenwich Mean Time (GMT) 
                  //and local time of Date object, in minutes.
                  var offset = new Date().getTimezoneOffset(); 
                  document.cookie = 'timezoneOffset=' + escape(offset);
                  

                  或者您可以让用户自行设置时区.

                  Or you could offer users the chioce to set their time zones themselves.

                  这篇关于处理不同时区的PHP服务器和MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 PHP 中处理在不同时区存储/显示日期的最佳方法? 下一篇:在 php 中获取服务器时间 - 时区问题

                  相关文章

                • <tfoot id='6BIFY'></tfoot>

                  <i id='6BIFY'><tr id='6BIFY'><dt id='6BIFY'><q id='6BIFY'><span id='6BIFY'><b id='6BIFY'><form id='6BIFY'><ins id='6BIFY'></ins><ul id='6BIFY'></ul><sub id='6BIFY'></sub></form><legend id='6BIFY'></legend><bdo id='6BIFY'><pre id='6BIFY'><center id='6BIFY'></center></pre></bdo></b><th id='6BIFY'></th></span></q></dt></tr></i><div id='6BIFY'><tfoot id='6BIFY'></tfoot><dl id='6BIFY'><fieldset id='6BIFY'></fieldset></dl></div>
                  • <bdo id='6BIFY'></bdo><ul id='6BIFY'></ul>

                  <legend id='6BIFY'><style id='6BIFY'><dir id='6BIFY'><q id='6BIFY'></q></dir></style></legend>

                      <small id='6BIFY'></small><noframes id='6BIFY'>