久久久久久久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 將帶偏移量的時間戳轉(zhuǎn)換為 datetime

      Convert timestamps with offset to datetime obj using strptime(使用 strptime 將帶偏移量的時間戳轉(zhuǎn)換為 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 將帶偏移量的時間戳轉(zhuǎn)換為 datetime obj的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在嘗試轉(zhuǎn)換格式為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() 函數(shù)確實不支持 %z 格式的時區(qū)(因為底層 time.strptime() 函數(shù)不支持).你有兩個選擇:

                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解析時忽略時區(qū):

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

              2. 使用 dateutil 模塊,它是解析函數(shù)確實處理時區(qū):

                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 或更高版本,其中的時區(qū)支持已經(jīng)改進到 %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)))
                

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

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

                相關(guān)文檔推薦

                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(如何在不重復(fù)導(dǎo)入頂級名稱的情況下構(gòu)造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(分發(fā)帶有已編譯動態(tài)共享庫的 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. 主站蜘蛛池模板: 狠狠草视频 | 奇米影视亚洲春色 | 99久久久国产精品免费蜜臀 | 亚洲一区网站 | av在线天堂 | 激情网五月天 | 亚洲欧美日韩精品 | 久久精品导航 | 天天视频黄 | 日韩天堂在线 | 久久r| 黄色成人毛片 | 亚洲成人免费在线观看 | 久久久噜噜噜 | 欧美日韩中文字幕 | 日韩免费精品视频 | 黑人精品一区二区 | 好吊视频一区二区三区 | 日本高清中文字幕 | 久久久www成人免费精品 | 99视频 | 欧美一级在线观看 | 国产精品亚洲精品 | 亚洲精品91 | 在线日韩一区 | 这里只有精品视频在线观看 | 91精品国产一区二区三区 | 伦一理一级一a一片 | 日韩免费高清 | 师生出轨h灌满了1v1 | 一级片免费在线观看 | 久操av在线 | 日韩网站在线观看 | 伊人在线 | 夜夜操夜夜爽 | 国产精品久久久久久99 | 国产午夜精品久久 | 在线观看国产一区二区 | 日本少妇久久 | www.日本高清 | 国产乱码久久久久久 |