小编Dea*_*ake的帖子

检查日期是否为没有 pytz 的时区的夏令时

由于某些原因,我的雇主不想使用 pip 安装第三方软件包,并希望我使用仅托管在 trusty 上的软件包。因此,我现在无法在代码中使用 pytz。我将如何检查时区中的某个日期是否采用夏令时?这是我使用 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
Run Code Online (Sandbox Code Playgroud)

python datetime python-3.x

6
推荐指数
1
解决办法
6764
查看次数

标签 统计

datetime ×1

python ×1

python-3.x ×1