1. <legend id='KqgEW'><style id='KqgEW'><dir id='KqgEW'><q id='KqgEW'></q></dir></style></legend>
    2. <small id='KqgEW'></small><noframes id='KqgEW'>

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

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

        pytz 本地化与日期时间替换

        时间:2023-07-03
      1. <small id='mQXLX'></small><noframes id='mQXLX'>

              <tbody id='mQXLX'></tbody>
              <bdo id='mQXLX'></bdo><ul id='mQXLX'></ul>

              <legend id='mQXLX'><style id='mQXLX'><dir id='mQXLX'><q id='mQXLX'></q></dir></style></legend>
              1. <tfoot id='mQXLX'></tfoot>

                <i id='mQXLX'><tr id='mQXLX'><dt id='mQXLX'><q id='mQXLX'><span id='mQXLX'><b id='mQXLX'><form id='mQXLX'><ins id='mQXLX'></ins><ul id='mQXLX'></ul><sub id='mQXLX'></sub></form><legend id='mQXLX'></legend><bdo id='mQXLX'><pre id='mQXLX'><center id='mQXLX'></center></pre></bdo></b><th id='mQXLX'></th></span></q></dt></tr></i><div id='mQXLX'><tfoot id='mQXLX'></tfoot><dl id='mQXLX'><fieldset id='mQXLX'></fieldset></dl></div>
                1. 本文介绍了pytz 本地化与日期时间替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在使用 pytz 的 .localize() 函数时遇到了一些奇怪的问题.有时它不会对本地化的日期时间进行调整:

                  I'm having some weird issues with pytz's .localize() function. Sometimes it wouldn't make adjustments to the localized datetime:

                  .localize 行为:

                  .localize behaviour:

                  >>> tz
                  <DstTzInfo 'Africa/Abidjan' LMT-1 day, 23:44:00 STD> 
                  >>> d
                  datetime.datetime(2009, 9, 2, 14, 45, 42, 91421)
                  
                  >>> tz.localize(d)
                  datetime.datetime(2009, 9, 2, 14, 45, 42, 91421, 
                                    tzinfo=<DstTzInfo 'Africa/Abidjan' GMT0:00:00 STD>)
                  >>> tz.normalize(tz.localize(d))
                  datetime.datetime(2009, 9, 2, 14, 45, 42, 91421,
                                    tzinfo=<DstTzInfo 'Africa/Abidjan' GMT0:00:00 STD>)
                  

                  如您所见,本地化/规范化操作并未改变时间.但是,如果使用 .replace:

                  As you can see, time has not been changed as a result of localize/normalize operations. However, if .replace is used:

                  >>> d.replace(tzinfo=tz)
                  datetime.datetime(2009, 9, 2, 14, 45, 42, 91421, 
                                    tzinfo=<DstTzInfo 'Africa/Abidjan' LMT-1 day, 23:44:00 STD>)
                  >>> tz.normalize(d.replace(tzinfo=tz))
                  datetime.datetime(2009, 9, 2, 15, 1, 42, 91421,
                                    tzinfo=<DstTzInfo 'Africa/Abidjan' GMT0:00:00 STD>)
                  

                  这似乎对日期时间进行了调整.

                  Which seems to make adjustments into datetime.

                  问题是 - 哪个是正确的,为什么其他人是错的?

                  Question is - which is correct and why other's wrong?

                  推荐答案

                  localize 只是假设您传递给它的天真日期时间是正确的"(除了不知道时区!)等等只是设置时区,没有其他调整.

                  localize just assumes that the naive datetime you pass it is "right" (except for not knowing about the timezone!) and so just sets the timezone, no other adjustments.

                  您可以(并且建议...)在 UTC 内部工作(而不是使用简单的日期时间)并在需要以本地化方式执行日期时间的 I/O 时使用 replace(normalize 将处理 DST 等).

                  You can (and it's advisable...) internally work in UTC (rather than with naive datetimes) and use replace when you need to perform I/O of datetimes in a localized way (normalize will handle DST and the like).

                  这篇关于pytz 本地化与日期时间替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:python - 如何在没有dateutil的情况下将时区感知字符串转换为Python中的日期时间? 下一篇:如何在python中将时区添加到天真的日期时间实例中

                  相关文章

                2. <small id='ZXIn0'></small><noframes id='ZXIn0'>

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

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

                      <tfoot id='ZXIn0'></tfoot>