我有一个 UTC 时间戳,我想检查当时伦敦是否是夏令时。我该如何在 Python 中做到这一点?
最佳答案
您可以使用 os.environ 设置时区。以下是检查两个不同时区的 DST 的示例:
import time, os
os.environ['TZ'] = 'Europe/London'
timestamp = os.path.getmtime(filename)
isdst = time.localtime(timestamp).tm_isdst > 0
In [973]: timestamp
Out[973]: 1571900789.0347116
In [965]: isdst
Out[965]: True
os.environ['TZ'] = 'USA/Colorado'
timestamp = os.path.getmtime(filename)
isdst = time.localtime(timestamp).tm_isdst > 0
In [968]: isdst
Out[968]: False
关于Python - 使用 UTC 时间戳检查是否是另一个时区的 DST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58774833/