描述
方法tzset()重置庫例程使用的時間轉換規則。環境變量 TZ 指定這是如何完成的。
TZ 環境變量的標準格式是(為清晰起見添加了空格) -
std offset [dst [offset [,start[/time], end[/time]]]]
std and dst- 給出時區縮寫的三個或更多字母數字。這些將傳播到 time.tzname 中。
offset− 偏移量的格式為:hh[:mm[:ss]]。這表示與到達 UTC 的本地時間相加的值。如果前麵有 '-',則時區在本初子午線以東;否則,它是西方。如果 dst 之後沒有偏移,則假定夏令時比標準時間提前 1 小時。
start[/time], end[/time]− 指示何時更改為和返回 DST。開始日期和結束日期的格式是以下之一 -
Jn− 儒略日 n (1 <= n <= 365)。閏日不計算在內,因此在所有年份中,2 月 28 日是第 59 天,3 月 1 日是第 60 天。
n− 從零開始的儒略日 (0 <= n <= 365)。閏日是計算的,可以參考2月29日。
Mm.n.d− 第 d 天 (0 <= d <= 6) 或一年中第 m 個月的第 n 周(1 <= n <= 5, 1 <= m <= 12,其中第 5 周表示“最後 d 天”在第 m' 個月,可能發生在第四周或第五周)。第 1 周是第 d 天發生的第一周。零日是星期日。
time− 除了不允許前導符號('-' 或 '+')之外,這與偏移具有相同的格式。如果未給出時間,則默認值為 02:00:00。
用法
以下是語法tzset()方法 -
time.tzset()
參數
NA
返回值
此方法不返回任何值。
示例
下麵的例子展示了 tzset() 方法的用法。
#!/usr/bin/python3
import time
import os
os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0'
time.tzset()
print (time.strftime('%X %x %Z'))
os.environ['TZ'] = 'AEST-10AEDT-11,M10.5.0,M3.5.0'
time.tzset()
print (time.strftime('%X %x %Z'))
結果
當我們運行上述程序時,它會產生以下結果 -
13:00:40 02/17/09 EST 05:00:40 02/18/09 AEDT
相關用法
- Python 3 time time()用法及代碼示例
- Python 3 time strftime()用法及代碼示例
- Python 3 time asctime()用法及代碼示例
- Python 3 time altzone()用法及代碼示例
- Python 3 time localtime()用法及代碼示例
- Python 3 time mktime()用法及代碼示例
- Python 3 time gmtime()用法及代碼示例
- Python 3 time sleep()用法及代碼示例
- Python 3 time ctime()用法及代碼示例
- Python 3 time strptime()用法及代碼示例
- Python 3 time clock()用法及代碼示例
- Python 3 Number tan()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 List pop()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 dictionary cmp()用法及代碼示例
- Python 3 String isupper()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 List index()用法及代碼示例
- Python 3 String decode()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - time tzset() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。