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

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

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

    <tfoot id='Y524I'></tfoot>

        如何使用 strptime 解析 str(my_datetime)?

        How to parse str(my_datetime) using strptime?(如何使用 strptime 解析 str(my_datetime)?)

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

              <tfoot id='tKmDt'></tfoot>
              <legend id='tKmDt'><style id='tKmDt'><dir id='tKmDt'><q id='tKmDt'></q></dir></style></legend>
                <tbody id='tKmDt'></tbody>
                • <bdo id='tKmDt'></bdo><ul id='tKmDt'></ul>

                  <i id='tKmDt'><tr id='tKmDt'><dt id='tKmDt'><q id='tKmDt'><span id='tKmDt'><b id='tKmDt'><form id='tKmDt'><ins id='tKmDt'></ins><ul id='tKmDt'></ul><sub id='tKmDt'></sub></form><legend id='tKmDt'></legend><bdo id='tKmDt'><pre id='tKmDt'><center id='tKmDt'></center></pre></bdo></b><th id='tKmDt'></th></span></q></dt></tr></i><div id='tKmDt'><tfoot id='tKmDt'></tfoot><dl id='tKmDt'><fieldset id='tKmDt'></fieldset></dl></div>
                • 本文介绍了如何使用 strptime 解析 str(my_datetime)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是 默认字符串表示日期时间:

                  >>> from datetime import datetime, timezone
                  >>> dt = datetime(2017, 1, 1, tzinfo=timezone.utc)
                  >>> print(dt)
                  2017-01-01 00:00:00+00:00
                  

                  datetime.strptime 解析的正确格式字符串是什么?也就是说,用什么格式代替???"?始终具有以下不变量:

                  What is the correct format string to parse that with datetime.strptime? That is, what format goes in place of the "???" to consistently have the following invariant:

                  >>> dt == datetime.strptime(str(dt), "???")
                  True
                  

                  推荐答案

                  注意 str(d) 被记录为等同于 d.isoformat(' ').这以 %Y-%m-%d %H:%M:%S (2017-01-01 00:00:00) 开头,然后:

                  Note that str(d) is documented as being equivalent to d.isoformat(' '). This starts with %Y-%m-%d %H:%M:%S (2017-01-01 00:00:00), but then:

                  • 要么没有,要么没有 .%f,这取决于微秒部分是否为非零.
                  • 根据实例是否支持时区,要么没有任何内容,要么没有类似 +HH:MM 的偏移量.
                  • Either has nothing or .%f, depending whether the microseconds part is nonzero.
                  • Either has nothing or an offset like +HH:MM, depending whether the instance is timezone-aware.

                  datetime.strptime 不支持可选部分,因此没有一个 format 参数可以匹配所有可能的输出.

                  datetime.strptime doesn't have support for optional parts, therefore there isn't a single format parameter that can match all of the possible outputs.

                  在 Python 3.7+ 中,您可以使用 datetime.fromisoformat 解析 datetime.isoformat 输出.由 Paul Ganssle 在 issue15873 中贡献.

                  In Python 3.7+, you can use datetime.fromisoformat to parse datetime.isoformat output. Contributed by Paul Ganssle in issue15873.

                  这篇关于如何使用 strptime 解析 str(my_datetime)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='CkG5Q'><tr id='CkG5Q'><dt id='CkG5Q'><q id='CkG5Q'><span id='CkG5Q'><b id='CkG5Q'><form id='CkG5Q'><ins id='CkG5Q'></ins><ul id='CkG5Q'></ul><sub id='CkG5Q'></sub></form><legend id='CkG5Q'></legend><bdo id='CkG5Q'><pre id='CkG5Q'><center id='CkG5Q'></center></pre></bdo></b><th id='CkG5Q'></th></span></q></dt></tr></i><div id='CkG5Q'><tfoot id='CkG5Q'></tfoot><dl id='CkG5Q'><fieldset id='CkG5Q'></fieldset></dl></div>

                      <tbody id='CkG5Q'></tbody>
                      • <bdo id='CkG5Q'></bdo><ul id='CkG5Q'></ul>

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

                        <tfoot id='CkG5Q'></tfoot>
                        <legend id='CkG5Q'><style id='CkG5Q'><dir id='CkG5Q'><q id='CkG5Q'></q></dir></style></legend>