久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

      <tfoot id='y2uA8'></tfoot>

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

        <bdo id='y2uA8'></bdo><ul id='y2uA8'></ul>
    1. 使用 strptime 將帶偏移量的時間戳轉換為 datetime

      Convert timestamps with offset to datetime obj using strptime(使用 strptime 將帶偏移量的時間戳轉換為 datetime obj)

        <tbody id='AWWEE'></tbody>
      1. <legend id='AWWEE'><style id='AWWEE'><dir id='AWWEE'><q id='AWWEE'></q></dir></style></legend>
            <bdo id='AWWEE'></bdo><ul id='AWWEE'></ul>
          • <i id='AWWEE'><tr id='AWWEE'><dt id='AWWEE'><q id='AWWEE'><span id='AWWEE'><b id='AWWEE'><form id='AWWEE'><ins id='AWWEE'></ins><ul id='AWWEE'></ul><sub id='AWWEE'></sub></form><legend id='AWWEE'></legend><bdo id='AWWEE'><pre id='AWWEE'><center id='AWWEE'></center></pre></bdo></b><th id='AWWEE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AWWEE'><tfoot id='AWWEE'></tfoot><dl id='AWWEE'><fieldset id='AWWEE'></fieldset></dl></div>

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

              1. <tfoot id='AWWEE'></tfoot>
                本文介紹了使用 strptime 將帶偏移量的時間戳轉換為 datetime obj的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試轉換格式為2012-07-24T23:14:29-07:00"的時間戳使用 strptime 方法到 python 中的日期時間對象.問題在于最后的時間偏移(-07:00).沒有偏移我可以成功

                I am trying to convert time-stamps of the format "2012-07-24T23:14:29-07:00" to datetime objects in python using strptime method. The problem is with the time offset at the end(-07:00). Without the offset i can successfully do

                time_str = "2012-07-24T23:14:29"
                
                time_obj=datetime.datetime.strptime(time_str,'%Y-%m-%dT%H:%M:%S')
                

                但是我嘗試了偏移量

                time_str = "2012-07-24T23:14:29-07:00"
                
                time_obj=datetime.datetime.strptime(time_str,'%Y-%m-%dT%H:%M:%S-%z').
                

                但它給出了一個值錯誤,說z"是一個錯誤的指令.

                But it gives a Value error saying "z" is a bad directive.

                有什么解決辦法嗎?

                推薦答案

                Python 2 strptime() 函數確實不支持 %z 格式的時區(因為底層 time.strptime() 函數不支持).你有兩個選擇:

                The Python 2 strptime() function indeed does not support the %z format for timezones (because the underlying time.strptime() function doesn't support it). You have two options:

                • 使用strptime解析時忽略時區:

                time_obj = datetime.datetime.strptime(time_str[:19], '%Y-%m-%dT%H:%M:%S')
                

              2. 使用 dateutil 模塊,它是解析函數確實處理時區:

                from dateutil.parser import parse
                time_obj = parse(time_str)
                

              3. 命令提示符下的快速演示:

                Quick demo on the command prompt:

                >>> from dateutil.parser import parse
                >>> parse("2012-07-24T23:14:29-07:00")
                datetime.datetime(2012, 7, 24, 23, 14, 29, tzinfo=tzoffset(None, -25200))
                

                您還可以升級到 Python 3.2 或更高版本,其中的時區支持已經改進到 %z 可以工作,前提是您從輸入,以及 %z 之前的 -:

                You could also upgrade to Python 3.2 or newer, where timezone support has been improved to the point that %z would work, provided you remove the last : from the input, and the - from before the %z:

                >>> import datetime
                >>> time_str = "2012-07-24T23:14:29-07:00"
                >>> datetime.datetime.strptime(time_str, '%Y-%m-%dT%H:%M:%S%z')
                Traceback (most recent call last):
                  File "<stdin>", line 1, in <module>
                  File "/Users/mj/Development/Library/buildout.python/parts/opt/lib/python3.4/_strptime.py", line 500, in _strptime_datetime
                    tt, fraction = _strptime(data_string, format)
                  File "/Users/mj/Development/Library/buildout.python/parts/opt/lib/python3.4/_strptime.py", line 337, in _strptime
                    (data_string, format))
                ValueError: time data '2012-07-24T23:14:29-07:00' does not match format '%Y-%m-%dT%H:%M:%S%z'
                >>> ''.join(time_str.rsplit(':', 1))
                '2012-07-24T23:14:29-0700'
                >>> datetime.datetime.strptime(''.join(time_str.rsplit(':', 1)), '%Y-%m-%dT%H:%M:%S%z')
                datetime.datetime(2012, 7, 24, 23, 14, 29, tzinfo=datetime.timezone(datetime.timedelta(-1, 61200)))
                

                這篇關于使用 strptime 將帶偏移量的時間戳轉換為 datetime obj的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                How to refresh sys.path?(如何刷新 sys.path?)
                Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)

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

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

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

                        1. 主站蜘蛛池模板: 日韩一级电影免费观看 | 久久成人激情 | 黄色在线免费观看 | 婷婷桃色网 | 精品一区二区三区电影 | 日韩精品极品视频在线观看免费 | 久热精品在线观看视频 | 91成人免费看片 | 国产精品1区2区3区 国产在线观看一区 | 国产韩国精品一区二区三区 | 特级a欧美做爰片毛片 | 99pao成人国产永久免费视频 | 一区二区三区四区毛片 | 99福利视频| 国产99久久精品一区二区永久免费 | 亚洲 中文 欧美 日韩 在线观看 | 在线中文字幕亚洲 | 日本免费在线观看视频 | av电影一区| 久久久婷婷 | 成人在线观看免费视频 | 久久久久久久久久久久久9999 | 精品一区二区三区在线观看 | 亚洲三区在线 | h视频在线免费看 | 亚洲免费毛片 | 成人免费观看男女羞羞视频 | 久久一 | 免费a大片 | 一区视频| 国产美女在线观看 | 国产免费一区二区 | 国产精品日韩高清伦字幕搜索 | 天天射天天操天天干 | 国产国语精品 | 日韩一区不卡 | 在线亚洲人成电影网站色www | 91视频国产精品 | h视频在线播放 | 91精品久久久久久久久 | 91久久综合 |