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

    1. <small id='4ArVG'></small><noframes id='4ArVG'>

      1. <legend id='4ArVG'><style id='4ArVG'><dir id='4ArVG'><q id='4ArVG'></q></dir></style></legend>

        PHP date() 与时区?

        PHP date() with timezone?(PHP date() 与时区?)

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

            <legend id='EX13q'><style id='EX13q'><dir id='EX13q'><q id='EX13q'></q></dir></style></legend>

                <tfoot id='EX13q'></tfoot>
                  <tbody id='EX13q'></tbody>
                  本文介绍了PHP date() 与时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我检查了 PHP 中支持的时区 列表,我是想知道如何将它们包含在 date() 函数中?谢谢!

                  So I've checked the list of supported time zones in PHP and I was wondering how could I include them in the date() function? Thanks!

                  我不想要默认时区,每个用户都将他们的时区存储在数据库中,我采用用户的时区并使用它.如何?不过,我知道如何从数据库中获取它,而不是如何使用它.

                  I don't want a default timezone, each user has their timezone stored in the database, I take that timezone of the user and use it. How? I know how to take it from the database, not how to use it, though.

                  推荐答案

                  对于这样的任务,你真的应该使用 PHP 的 DateTime 类.请忽略所有建议您使用 date() 或 date_set_time_zone 的答案,这简直是糟糕且过时的.

                  For such task, you should really be using PHP's DateTime class. Please ignore all of the answers advising you to use date() or date_set_time_zone, it's simply bad and outdated.

                  我将使用伪代码进行演示,因此请尝试调整代码以满足您的需求.

                  I'll use pseudocode to demonstrate, so try to adjust the code to suit your needs.

                  假设变量 $tz 包含有效时区的字符串名称,变量 $timestamp 包含您希望根据时区格式化的时间戳,代码如下所示:

                  Assuming that variable $tz contains string name of a valid time zone and variable $timestamp contains the timestamp you wish to format according to time zone, the code would look like this:

                  $tz = 'Europe/London';
                  $timestamp = time();
                  $dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
                  $dt->setTimestamp($timestamp); //adjust the object to correct timestamp
                  echo $dt->format('d.m.Y, H:i:s');
                  

                  DateTime 类很强大,并且要掌握它的所有功能 - 您应该花一些时间在 php.net 上阅读它.要完全回答您的问题 - 是的,您可以动态调整时区参数(在从 db 读取时的每次迭代中,您可以创建一个新的 DateTimeZone() 对象).

                  DateTime class is powerful, and to grasp all of its capabilities - you should devote some of your time reading about it at php.net. To answer your question fully - yes, you can adjust the time zone parameter dynamically (on each iteration while reading from db, you can create a new DateTimeZone() object).

                  这篇关于PHP date() 与时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                      1. <i id='zeKps'><tr id='zeKps'><dt id='zeKps'><q id='zeKps'><span id='zeKps'><b id='zeKps'><form id='zeKps'><ins id='zeKps'></ins><ul id='zeKps'></ul><sub id='zeKps'></sub></form><legend id='zeKps'></legend><bdo id='zeKps'><pre id='zeKps'><center id='zeKps'></center></pre></bdo></b><th id='zeKps'></th></span></q></dt></tr></i><div id='zeKps'><tfoot id='zeKps'></tfoot><dl id='zeKps'><fieldset id='zeKps'></fieldset></dl></div>

                          <legend id='zeKps'><style id='zeKps'><dir id='zeKps'><q id='zeKps'></q></dir></style></legend>
                            <tbody id='zeKps'></tbody>
                            <bdo id='zeKps'></bdo><ul id='zeKps'></ul>
                          • <tfoot id='zeKps'></tfoot>

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