• <tfoot id='2gMZp'></tfoot>
  • <small id='2gMZp'></small><noframes id='2gMZp'>

          <bdo id='2gMZp'></bdo><ul id='2gMZp'></ul>

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

        pytz:为什么在时区之间转换时需要规范化?

        pytz: Why is normalize needed when converting between timezones?(pytz:为什么在时区之间转换时需要规范化?)

        <tfoot id='LvveJ'></tfoot>
        • <bdo id='LvveJ'></bdo><ul id='LvveJ'></ul>
            <tbody id='LvveJ'></tbody>

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

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

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

                • 本文介绍了pytz:为什么在时区之间转换时需要规范化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在阅读不太完整的 pytz 文档,但我一直坚持理解其中的一部分.

                  I'm reading the not so complete pytz documentation and I'm stuck on understand one part of it.

                  时区之间的转换也需要特别注意.这也需要使用 normalize 方法来保证转换正确.

                  Converting between timezones also needs special attention. This also needs to use the normalize method to ensure the conversion is correct.

                  >>> utc_dt = utc.localize(datetime.utcfromtimestamp(1143408899))
                  >>> utc_dt.strftime(fmt)
                  '2006-03-26 21:34:59 UTC+0000'
                  >>> au_tz = timezone('Australia/Sydney')
                  >>> au_dt = au_tz.normalize(utc_dt.astimezone(au_tz))
                  >>> au_dt.strftime(fmt)
                  '2006-03-27 08:34:59 EST+1100'
                  >>> utc_dt2 = utc.normalize(au_dt.astimezone(utc))
                  >>> utc_dt2.strftime(fmt)
                  '2006-03-26 21:34:59 UTC+0000'
                  

                  我使用 normalize 尝试了这个示例 without,结果还是一样.在我看来,这个例子并没有真正解释为什么在不同时区的datetime对象之间进行转换时,我们必须使用normalize.

                  I tried this very example without using normalize and it turned out just the same. In my opinion this example doesn't really explain why we have to use normalize when converting between datetime objects in different timezones.

                  谁能给我一个示例(如上面的示例),当不使用 normalize 时结果会有所不同.

                  Would someone please give me an example (like the one above) where the result differs when not using normalize.

                  谢谢

                  推荐答案

                  来自 pytz 文档:

                  From the pytz documentation:

                  此外,如果您对跨越 DST 边界的本地时间执行日期算术,则结果可能位于不正确的时区(即,从 2002-10-27 1:00 EST 减去 1 分钟,得到 2002-10-27 0:59 EST 而不是正确的 2002-10-27 1:59 EDT).提供了一个 normalize() 方法来纠正这个问题.不幸的是,如果不修改 Python 日期时间实现,就无法解决这些问题.

                  In addition, if you perform date arithmetic on local times that cross DST boundaries, the results may be in an incorrect timezone (ie. subtract 1 minute from 2002-10-27 1:00 EST and you get 2002-10-27 0:59 EST instead of the correct 2002-10-27 1:59 EDT). A normalize() method is provided to correct this. Unfortunately these issues cannot be resolved without modifying the Python datetime implementation.

                  这篇关于pytz:为什么在时区之间转换时需要规范化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)
                  <i id='zNNDr'><tr id='zNNDr'><dt id='zNNDr'><q id='zNNDr'><span id='zNNDr'><b id='zNNDr'><form id='zNNDr'><ins id='zNNDr'></ins><ul id='zNNDr'></ul><sub id='zNNDr'></sub></form><legend id='zNNDr'></legend><bdo id='zNNDr'><pre id='zNNDr'><center id='zNNDr'></center></pre></bdo></b><th id='zNNDr'></th></span></q></dt></tr></i><div id='zNNDr'><tfoot id='zNNDr'></tfoot><dl id='zNNDr'><fieldset id='zNNDr'></fieldset></dl></div>

                    • <legend id='zNNDr'><style id='zNNDr'><dir id='zNNDr'><q id='zNNDr'></q></dir></style></legend>

                      1. <tfoot id='zNNDr'></tfoot>

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

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

                              <tbody id='zNNDr'></tbody>