<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國際加速解決方案。 廣告
                # Python 獲取當前時間 > 原文: [https://www.programiz.com/python-programming/datetime/current-time](https://www.programiz.com/python-programming/datetime/current-time) #### 在本文中,您將學習獲取語言環境的當前時間以及 Python 中的不同時區。 您可以采用多種方法獲取 Python 當前時間。 * * * ## 示例 1:使用`datetime`對象的當前時間 ```py from datetime import datetime now = datetime.now() current_time = now.strftime("%H:%M:%S") print("Current Time =", current_time) ``` 在上面的示例中,我們從[日期時間](/python-programming/datetime)模塊中導入了`datetime`類。 然后,我們使用`now()`方法獲取包含當前日期和時間的`datetime`對象。 然后,使用[`datetime.strftime()`](/python-programming/datetime/strftime)方法,創建一個表示當前時間的字符串。 * * * 如果您需要創建一個包含當前時間的`time`對象,則可以執行以下操作。 ```py from datetime import datetime now = datetime.now().time() # time object print("now =", now) print("type(now) =", type(now)) ``` * * * ## 示例 2:使用時間模塊的當前時間 您還可以使用時間模塊獲取當前時間。 ```py import time t = time.localtime() current_time = time.strftime("%H:%M:%S", t) print(current_time) ``` * * * ## 示例 3:時區的當前時間 如果需要查找某個時區的當前時間,可以使用[`pytz`模塊](http://pytz.sourceforge.net/)。 ```py from datetime import datetime import pytz tz_NY = pytz.timezone('America/New_York') datetime_NY = datetime.now(tz_NY) print("NY time:", datetime_NY.strftime("%H:%M:%S")) tz_London = pytz.timezone('Europe/London') datetime_London = datetime.now(tz_London) print("London time:", datetime_London.strftime("%H:%M:%S")) ```
                  <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>

                              哎呀哎呀视频在线观看