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

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

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

      <tfoot id='dsVkW'></tfoot>

        为什么 pytz localize() 不生成一个 tzinfo 与本地化它的 tz 对象匹配的 datetime 对象

        时间:2023-07-03

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

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

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

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

                <tfoot id='QJuI8'></tfoot>
                  本文介绍了为什么 pytz localize() 不生成一个 tzinfo 与本地化它的 tz 对象匹配的 datetime 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有人可以帮助我了解这里发生了什么?

                  Is there anyone who can help me understand what's going on here?

                  import pytz
                  from datetime import datetime
                  tz = pytz.timezone('Europe/Berlin')
                  print repr(tz)
                  # <DstTzInfo 'Europe/Berlin' LMT+0:53:00 STD>
                  dt = datetime(2011, 1, 3, 18, 40)
                  result = tz.localize(dt)
                  print repr(result.tzinfo)
                  # <DstTzInfo 'Europe/Berlin' CET+1:00:00 STD>
                  assert result.tzinfo == tz, "Why aren't these the same timezone?"
                  

                  我的理解是,pytz 时区对象上的 localize() 方法将采用一个简单的 datetime 对象,并添加一个与执行时区对象相匹配的 tzinfo 属性本土化.在这种情况下似乎没有发生这种情况.

                  My understanding was that the localize() method on a pytz timezone object would take a naive datetime object, and add a tzinfo property that matches the timezone object performing the localization. That does not appear to be happening in this case.

                  显然,我对时区或 pytz 处理时区的方式有一些误解.谁能解释一下?

                  Clearly, there's something I'm misunderstanding about timezones, or about the way that pytz handles timezones. Can anyone explain?

                  推荐答案

                  它们相同的时区 - "Europe/Berlin".

                  They are the same time zone - "Europe/Berlin".

                  当您打印它们时,输出包括在该特定时间点应用的缩写和偏移量.

                  When you are printing them, the output includes the abbreviation and offset that applies at that particular point in time.

                  如果您检查 tz 数据源,您会发现会看到:

                  If you examine the tz data sources, you'll see:

                  # Zone  NAME            GMTOFF   RULES       FORMAT   [UNTIL]
                  Zone    Europe/Berlin   0:53:28  -           LMT      1893 Apr
                                          1:00     C-Eur       CE%sT    1945 May 24 2:00
                                          1:00     SovietZone  CE%sT    1946
                                          1:00     Germany     CE%sT    1980
                                          1:00     EU          CE%sT
                  

                  所以看起来当时区没有本地化日期时间时,它只使用第一个条目.

                  So it would appear that when the time zone has not localized a datetime, then it just uses the first entry.

                  看起来 pytz 并没有保留原始本地平均时间偏差的额外 28 秒 - 但这并不重要,除非您使用的是 1893 年 4 月之前在柏林的日期.

                  It would also appear that pytz doesn't retain the extra 28 seconds from the original local mean time deviation - but that doesn't matter unless you are working with dates in Berlin before April 1893.

                  这篇关于为什么 pytz localize() 不生成一个 tzinfo 与本地化它的 tz 对象匹配的 datetime 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 Python 中将天真的日期时间转换为可识别 DST 的日期时间? 下一篇:如何将 datetime.time 从 UTC 转换为不同的时区?

                  相关文章

                  <small id='1dm6Q'></small><noframes id='1dm6Q'>

                      <legend id='1dm6Q'><style id='1dm6Q'><dir id='1dm6Q'><q id='1dm6Q'></q></dir></style></legend>

                      • <bdo id='1dm6Q'></bdo><ul id='1dm6Q'></ul>

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