<legend id='0uBiG'><style id='0uBiG'><dir id='0uBiG'><q id='0uBiG'></q></dir></style></legend>

          <bdo id='0uBiG'></bdo><ul id='0uBiG'></ul>
        <tfoot id='0uBiG'></tfoot>

        <i id='0uBiG'><tr id='0uBiG'><dt id='0uBiG'><q id='0uBiG'><span id='0uBiG'><b id='0uBiG'><form id='0uBiG'><ins id='0uBiG'></ins><ul id='0uBiG'></ul><sub id='0uBiG'></sub></form><legend id='0uBiG'></legend><bdo id='0uBiG'><pre id='0uBiG'><center id='0uBiG'></center></pre></bdo></b><th id='0uBiG'></th></span></q></dt></tr></i><div id='0uBiG'><tfoot id='0uBiG'></tfoot><dl id='0uBiG'><fieldset id='0uBiG'></fieldset></dl></div>
      1. <small id='0uBiG'></small><noframes id='0uBiG'>

      2. 在 PHP 中猜测用户的时区

        Guessing User#39;s TimeZone in PHP(在 PHP 中猜测用户的时区)

        • <bdo id='gKdgL'></bdo><ul id='gKdgL'></ul>
            <tbody id='gKdgL'></tbody>

              1. <small id='gKdgL'></small><noframes id='gKdgL'>

              2. <tfoot id='gKdgL'></tfoot>
              3. <legend id='gKdgL'><style id='gKdgL'><dir id='gKdgL'><q id='gKdgL'></q></dir></style></legend>

              4. <i id='gKdgL'><tr id='gKdgL'><dt id='gKdgL'><q id='gKdgL'><span id='gKdgL'><b id='gKdgL'><form id='gKdgL'><ins id='gKdgL'></ins><ul id='gKdgL'></ul><sub id='gKdgL'></sub></form><legend id='gKdgL'></legend><bdo id='gKdgL'><pre id='gKdgL'><center id='gKdgL'></center></pre></bdo></b><th id='gKdgL'></th></span></q></dt></tr></i><div id='gKdgL'><tfoot id='gKdgL'></tfoot><dl id='gKdgL'><fieldset id='gKdgL'></fieldset></dl></div>
                  本文介绍了在 PHP 中猜测用户的时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  从 PHP5.3 开始(我认为),date.timezone 需要在 php.ini 文件中设置,或者设置为运行时通过 date_default_timezone_set() 函数.当您不设置此值时,您会得到一个错误,类似于以下内容:

                  <块引用>

                  PHP 警告:date(): 依赖系统的时区设置是不安全的.您必须使用 date.timezone 设置或 date_default_timezone_set() 函数.如果您使用了这些方法中的任何一种,但仍然收到此警告,您很可能拼错了时区标识符.我们在 LINE 行的 FILE 中选择了America/New_York"作为-4.0/DST".

                  我想知道它使用什么机制来猜测时区,因为它似乎非常准确,我想自己知道,以便我可以以更友好的方式向用户呈现此错误,或者让他们接受这是正确的时区.

                  解决方案

                  我可能会使用 date_default_timezone_get() 函数:

                  <块引用>

                  string date_default_timezone_get ( void )

                  按优先顺序,此功能通过以下方式返回默认时区:

                  • 使用 date_default_timezone_set() 读取时区设置功能(如果有)
                  • 读取 TZ 环境变量(如果非空)(PHP 之前5.3.0)
                  • 读取 date.timezone ini 选项的值(如果已设置)
                  • 查询主机操作系统(如果支持并允许操作系统)

                  http://www.php.net/manual/en/function.date-default-timezone-get.php

                  As of PHP5.3 (I think) it became a requirement for the date.timezone to be set in the php.ini file, or to be set at runtime via the date_default_timezone_set() function. When you don't set this value you get, an error, something along the lines of this:

                  PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for '-4.0/DST' instead in FILE on line LINE.

                  I was wondering what mechanism it uses to guess the timezone, as it seems to be pretty accurate, and I wanted to know for myself so I can present this error in a more friendly way to the user, or allow them to accept this as the correct timezone.

                  解决方案

                  I'd probably use the date_default_timezone_get() function:

                  string date_default_timezone_get  ( void  )
                  

                  In order of preference, this function returns the default timezone by:

                  • Reading the timezone set using the date_default_timezone_set() function (if any)
                  • Reading the TZ environment variable (if non empty) (Prior to PHP 5.3.0)
                  • Reading the value of the date.timezone ini option (if set)
                  • Querying the host operating system (if supported and allowed by the OS)

                  http://www.php.net/manual/en/function.date-default-timezone-get.php

                  这篇关于在 PHP 中猜测用户的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  • <bdo id='QCL5p'></bdo><ul id='QCL5p'></ul>

                      <legend id='QCL5p'><style id='QCL5p'><dir id='QCL5p'><q id='QCL5p'></q></dir></style></legend>
                        <tfoot id='QCL5p'></tfoot>

                          1. <small id='QCL5p'></small><noframes id='QCL5p'>

                              <tbody id='QCL5p'></tbody>
                          2. <i id='QCL5p'><tr id='QCL5p'><dt id='QCL5p'><q id='QCL5p'><span id='QCL5p'><b id='QCL5p'><form id='QCL5p'><ins id='QCL5p'></ins><ul id='QCL5p'></ul><sub id='QCL5p'></sub></form><legend id='QCL5p'></legend><bdo id='QCL5p'><pre id='QCL5p'><center id='QCL5p'></center></pre></bdo></b><th id='QCL5p'></th></span></q></dt></tr></i><div id='QCL5p'><tfoot id='QCL5p'></tfoot><dl id='QCL5p'><fieldset id='QCL5p'></fieldset></dl></div>