提问人:SagittariusAStar_MW 提问时间:5/25/2020 最后编辑:FObersteinerSagittariusAStar_MW 更新时间:5/25/2020 访问量:3387
Python 3:Windows 的 time.tzset() 替代品?
Python 3: time.tzset() alternative for Windows?
问:
我是 Python 的新手。我正在阅读 Doug Hellmann 的可爱书“Python 3 标准库示例”中的日期和时间,我偶然发现了以下代码片段:
import time
import os
def show_zone_info():
print(f'''\
TZ : {os.environ.get('TZ', '(not set)')}
tzname: {time.tzname}
Zone : {time.timezone} ({time.timezone / 3600})
DST : {time.daylight}
Time : {time.ctime()}
''')
if __name__ == '__main__':
print('Default: ')
show_zone_info()
ZONES = [
'GMT',
'Europe/Amsterdam'
]
for zone in ZONES:
os.environ['TZ'] = zone
# time.tzset() # Only available on Unix
print(zone, ':')
show_zone_info()
问题是,仅在 Unix 上可用,在 Windows 机器上没有它,时区在代码运行时不会更改。在 Windows 上有什么替代方案?(在提出这个问题时,我正在 Windows 3.8.3 上运行 Python 10。time.tzset()
time.tzset()
答: 暂无答案
评论
os.environ['TZ']
localtime()
os.environ['TZ']
tzset()
tzset()