<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中获取时区感知当前时间的最简单和最连贯的方法?

        Python - simplest and most coherent way to get timezone-aware current time in UTC?(Python - 在UTC中获取时区感知当前时间的最简单和最连贯的方法?)

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

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

                  相关文档推荐

                  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% 就足够了)
                    <tbody id='dUTmX'></tbody>

                  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>

                          • <tfoot id='dUTmX'></tfoot>