<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] <br> ### time & datetime 模塊 time模塊,提供各種函數來操作時間值 datetime模塊,提供各種函數來操作日期值 ```python import time import datetime ``` #### case1:獲取當前時間并轉換為指定日期格式,如"2018-07-07 22:03:19" ```python # 獲得當前時間時間戳,如 1530972062 timeStamp = int(time.time()) # 返回 struct time 對象 timeArray = time.localtime(timeStamp) # 返回格式化時間如:2018-07-07 22:01:02 print(time.strftime("%Y-%m-%d %H:%M:%S", timeArray)) # 返回格式化時間如:2018-07-07 22:03:19 print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) ``` #### case2:將字符串的時間轉換為時間戳 ```python now = "2018-07-07 22:01:02" # 返回 struct_time 對象 timeArray = time.strptime(now, "%Y-%m-%d %H:%M:%S") # 返回時間戳:1530972062 timeStamp = int(time.mktime(timeArray)) ``` #### case3:獲取當前時間并轉換為指定日期格式,如"2018-07-07 22:07:46" ```python now = datetime.datetime.now() # 返回格式化日期格式 '2018-07-07 22:07:46' print(now.strftime("%Y-%m-%d %H:%M:%S")) ``` #### case4:時間戳直接轉成日期格式 2018-07-07 ```python print(datetime.date.fromtimestamp(time.time())) # 2018-07-07 ``` #### case5:獲得三天前時間 ```python # datetime.datetime(2018, 7, 4, 22, 9, 45, 791649) threeDayAgo = (datetime.datetime.now() - datetime.timedelta(days=3)) # 轉換為時間戳 1530713385 timeStamp = int(time.mktime(threeDayAgo.timetuple())) # 轉為其他字符串格式 '2018-07-04 22:09:45' otherStyleTime = threeDayAgo.strftime("%Y-%m-%d %H:%M:%S") ``` ### 時間轉換過程 ![](https://box.kancloud.cn/765482f45b1948e43ec8ceacf964fd46_785x428.jpg) <hr style="margin-top:100px"> :-: ![](https://box.kancloud.cn/2ff0bc02ec938fef8b6dd7b7f16ee11d_258x258.jpg) ***微信掃一掃,關注“python測試開發圈”,了解更多測試教程!***
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看