Python altzone() 方法用於返回本地 DST 時區的偏移量,以 UTC 以西的秒數為單位。我們還可以通過使用 timezone 和 altzone 方法獲取當前時區和 UTC 之間的當前時間。
用法:
time.altzone
例:
Python3
# import the time module
import time
# display altzone
print(time.altzone)
輸出:
25200
例:Python程序通過使用時區和altzone方法獲取當前時區和UTC之間的當前時間
Python3
# import time module
import time
# get_zone function to get the
# current time between current time zone and UTC
# by using timezone and altzone method
def get_zone():
dst = time.daylight and time.localtime().tm_isdst
# get altzone if there exists dst otherwise
# get timezone
offset = time.altzone if dst else time.timezone
# check if offset greater than 0
westerly = offset > 0
# get the minutes and seconds
minutes, seconds = divmod(abs(offset), 60)
hours, minutes = divmod(minutes, 60)
# return the timezone
return '{}{:02d}{:02d}'.format('-' if westerly else '+', hours, minutes)
# call the function
get_zone()
輸出:
+0000
相關用法
- Python time.time()用法及代碼示例
- Python time.monotonic()用法及代碼示例
- Python time.get_clock_info()用法及代碼示例
- Python time.asctime()用法及代碼示例
- Python time.localtime()用法及代碼示例
- Python time.time_ns()用法及代碼示例
- Python time.clock_getres()用法及代碼示例
- Python time.process_time_ns()用法及代碼示例
- Python time.monotonic_ns()用法及代碼示例
- Python time.clock_settime_ns()用法及代碼示例
- Python time.clock_settime()用法及代碼示例
- Python time.clock_gettime_ns()用法及代碼示例
注:本文由純淨天空篩選整理自ojaswilavu8128大神的英文原創作品 Python time altzone() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。