<tfoot id='Oxr1D'></tfoot>

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

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

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

        Python - 在UTC中获取时区感知当前时间的最简单和最连贯的方法?

        时间:2023-07-03

        <legend id='SnO6d'><style id='SnO6d'><dir id='SnO6d'><q id='SnO6d'></q></dir></style></legend>
          <bdo id='SnO6d'></bdo><ul id='SnO6d'></ul>

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

                  <tfoot id='SnO6d'></tfoot>
                  本文介绍了Python - 在UTC中获取时区感知当前时间的最简单和最连贯的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  datetime.now() 似乎没有附加时区信息.我想要UTC的当前时间.我该怎么办?

                  datetime.now() doesn't appear to have timezone info attached. I want the current time in UTC. What do I do?

                  >>> from datetime import datetime
                  >>> y = datetime.now()
                  >>> y
                  datetime.datetime(2014, 3, 11, 11, 18, 33, 598489)
                  

                  起初我认为 datetime.utcnow() 是显而易见的解决方案,但后来我发现它也没有附加时区信息(WTF?).

                  At first I thought datetime.utcnow() was the obvious solution, but then I discovered that it doesn't have timezone info attached either (WTF?).

                  >>> from datetime import datetime
                  >>> y = datetime.utcnow()
                  >>> y
                  datetime.datetime(2014, 3, 11, 16, 19, 40, 238810)
                  

                  推荐答案

                  我用 pytz

                  然后使用以下代码

                  import pytz
                  from datetime import datetime
                  now = datetime.utcnow().replace(tzinfo = pytz.utc)
                  

                  这篇关于Python - 在UTC中获取时区感知当前时间的最简单和最连贯的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何获取 pytz 时区的通用名称,例如.美国/纽约的 EST/EDT 下一篇:pytz 等/GMT-5

                  相关文章

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

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

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

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