<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时间戳

        时间:2024-08-15
        <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时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 JavaScript 或 PHP 自动检测用户当前的本地时间 下一篇:php:通过 UTC 偏移量设置时区

                  相关文章

                  • <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'>