【发布时间】:2016-08-02 14:08:41
【问题描述】:
出于某些原因,我的雇主不想使用 pip 来安装第三方软件包,而是希望我使用仅托管在 trusty 上的软件包。因此,我现在不能在我的代码中使用 pytz。我将如何检查时区中的某个日期是否在 DST 中?这是我使用 pytz 的原始代码。
import pytz
import datetime
...
target_date = datetime.datetime.strptime(arg_date, "%Y-%m-%d")
time_zone = pytz.timezone('US/Eastern')
dst_date = time_zone.localize(target_date, is_dst=None)
est_hour = 24
if bool(dst_date.dst()) is True:
est_hour -= 4
else:
est_hour -= 5
【问题讨论】:
-
您是只担心美国时区还是需要在全球范围内运营?
-
我唯一关心的时区是美国东部。
标签: python python-3.x datetime