• <tfoot id='e84f3'></tfoot>
  • <legend id='e84f3'><style id='e84f3'><dir id='e84f3'><q id='e84f3'></q></dir></style></legend>
  • <small id='e84f3'></small><noframes id='e84f3'>

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

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

        使用 pytz 进行日期时间和时区转换 - 令人兴奋的行为

        时间:2023-07-03
        <legend id='sCs9U'><style id='sCs9U'><dir id='sCs9U'><q id='sCs9U'></q></dir></style></legend>

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

            <tbody id='sCs9U'></tbody>
          <tfoot id='sCs9U'></tfoot>

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

              • <bdo id='sCs9U'></bdo><ul id='sCs9U'></ul>

                  本文介绍了使用 pytz 进行日期时间和时区转换 - 令人兴奋的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将时区感知 datetime 对象转换为 UTC,然后再转换回原来的时区.我有以下片段

                  I'm trying to convert timezone aware datetime object to UTC and then back to it's original timezone. I have a following snippet

                  t = datetime(
                      2013, 11, 22, hour=11, minute=0,
                      tzinfo=pytz.timezone('Europe/Warsaw')
                  )
                  

                  现在在 ipython 中:

                  now in ipython:

                  In [18]: t
                  Out[18]: datetime.datetime(
                      2013, 11, 22, 11, 0, tzinfo=<DstTzInfo 'Europe/Warsaw' WMT+1:24:00 STD>
                  )
                  

                  现在让我们尝试转换为 UTC 并返回.我希望具有与以下相同的表示:

                  and now let's try to do conversion to UTC and back. I would expect to have the same representation as:

                  In [19]: t.astimezone(pytz.utc).astimezone(pytz.timezone('Europe/Warsaw'))
                  Out[19]: datetime.datetime(
                      2013, 11, 22, 10, 36, tzinfo=<DstTzInfo 'Europe/Warsaw' CET+1:00:00 STD>
                  )
                  

                  然而我们看到 Out[18]Out[19] 不同.怎么回事?

                  Yet we see that Out[18] and Out[19] differ. What's going on?

                  推荐答案

                  文档 http://pytz.sourceforge.net/ 声明不幸的是,对于许多时区,使用标准日期时间构造函数的 tzinfo 参数对 pytz '不起作用'."代码:

                  The documentation http://pytz.sourceforge.net/ states "Unfortunately using the tzinfo argument of the standard datetime constructors 'does not work' with pytz for many timezones." The code:

                  t = datetime(
                      2013, 5, 11, hour=11, minute=0,
                      tzinfo=pytz.timezone('Europe/Warsaw')
                  )
                  

                  按照这个不行,你应该使用localize方法:

                  doesn't work according to this, instead you should use the localize method:

                  t = pytz.timezone('Europe/Warsaw').localize(
                          datetime(2013, 5, 11, hour=11, minute=0))
                  

                  这篇关于使用 pytz 进行日期时间和时区转换 - 令人兴奋的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 pandas to_datetime 中使用时区 下一篇:使用 Python 找出当前是否处于夏令时的时区

                  相关文章

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

                  <tfoot id='tNfoa'></tfoot>
                • <legend id='tNfoa'><style id='tNfoa'><dir id='tNfoa'><q id='tNfoa'></q></dir></style></legend>

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