<tfoot id='lm3OB'></tfoot>

    <bdo id='lm3OB'></bdo><ul id='lm3OB'></ul>

      <legend id='lm3OB'><style id='lm3OB'><dir id='lm3OB'><q id='lm3OB'></q></dir></style></legend>
    1. <i id='lm3OB'><tr id='lm3OB'><dt id='lm3OB'><q id='lm3OB'><span id='lm3OB'><b id='lm3OB'><form id='lm3OB'><ins id='lm3OB'></ins><ul id='lm3OB'></ul><sub id='lm3OB'></sub></form><legend id='lm3OB'></legend><bdo id='lm3OB'><pre id='lm3OB'><center id='lm3OB'></center></pre></bdo></b><th id='lm3OB'></th></span></q></dt></tr></i><div id='lm3OB'><tfoot id='lm3OB'></tfoot><dl id='lm3OB'><fieldset id='lm3OB'></fieldset></dl></div>

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

        如何根据时区在php中获取Unix时间戳

        How to get Unix timestamp in php based on timezone(如何根据时区在php中获取Unix时间戳)
        <tfoot id='DjK5J'></tfoot>
            <bdo id='DjK5J'></bdo><ul id='DjK5J'></ul>
            <legend id='DjK5J'><style id='DjK5J'><dir id='DjK5J'><q id='DjK5J'></q></dir></style></legend>

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

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

                • 本文介绍了如何根据时区在php中获取Unix时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  代码优先

                      echo time() . '<br/>';
                  echo date('Y-m-d H:i:s') . '<br/>';
                  date_default_timezone_set('America/New_York'); 
                  
                  echo time() . '<br/>';
                  print_r($timezones[$timezone] . '<br/>');
                  echo date('Y-m-d H:i:s') . '<br/>';
                  

                  在上面的代码中,日期是根据时区打印的,但 unix 时间戳是相同的,即使设置了默认时区

                  In the above code the date is printed according to timezone but unix timestamp is same even after setting default timezone

                  如何根据时区打印unix时间戳?

                  How can we print unix timestamp according to timezone?

                  推荐答案

                  Volkerk 提供的答案(说时间戳总是基于 UTC)是正确的,但如果你真的需要一个解决方法(制作基于时区的时间戳) 看看我的例子.

                  The answer provided by Volkerk (that says timestamps are meant to be always UTC based) is correct, but if you really need a workaround (to make timezone based timestamps) look at my example.

                  <?php
                  
                  //default timezone
                  $date = new DateTime(null);
                  echo 'Default timezone: '.$date->getTimestamp().'<br />'."
                  ";
                  
                  //America/New_York
                  $date = new DateTime(null, new DateTimeZone('America/New_York'));
                  echo 'America/New_York: '.$date->getTimestamp().'<br />'."
                  ";
                  
                  //Europe/Amsterdam
                  $date = new DateTime(null, new DateTimeZone('Europe/Amsterdam'));
                  echo 'Europe/Amsterdam: '.$date->getTimestamp().'<br />'."
                  ";
                  
                  echo 'WORK AROUND<br />'."
                  ";
                  // WORK AROUND
                  //default timezone
                  $date = new DateTime(null);
                  echo 'Default timezone: '.($date->getTimestamp() + $date->getOffset()).'<br />'."
                  ";
                  
                  //America/New_York
                  $date = new DateTime(null, new DateTimeZone('America/New_York'));
                  echo 'America/New_York: '.($date->getTimestamp() + $date->getOffset()).'<br />'."
                  ";
                  
                  //Europe/Amsterdam
                  $date = new DateTime(null, new DateTimeZone('Europe/Amsterdam'));
                  echo 'Europe/Amsterdam: '.($date->getTimestamp() + $date->getOffset()).'<br />'."
                  ";
                  ?>
                  

                  获取常规时间戳并添加 UTC 偏移量

                  Get the regular timestamp and add the UTC offset

                  这篇关于如何根据时区在php中获取Unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='hRwZr'></bdo><ul id='hRwZr'></ul>
                  • <legend id='hRwZr'><style id='hRwZr'><dir id='hRwZr'><q id='hRwZr'></q></dir></style></legend>

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

                        2. <tfoot id='hRwZr'></tfoot>

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

                              <tbody id='hRwZr'></tbody>