gpt4 book ai didi

python - 当 pytz.timezone() 传递给 tzinfo 时,pytz 返回 LMT 时区而不是 GMT

转载 作者:行者123 更新时间:2023-12-02 16:10:09 28 4
gpt4 key购买 nike

<分区>

from datetime import datetime
from pytz import timezone
d1 = datetime.now(tz = timezone('Asia/Calcutta'))
d2 = datetime(2019,12,12,12,12,12,12)
zone = timezone('Asia/Calcutta')
d2 = zone.localize(d2)
d3 = datetime(2019,12,12,12,12,12,12,tzinfo = timezone('Asia/Calcutta'))
print(d1,d1.tzinfo.tzname)
print(d2,d2.tzinfo.tzname)
print(d3,d3.tzinfo.tzname)

这是我得到的结果

2021-07-03 14:00:03.135000+05:30 <bound method DstTzInfo.tzname of <DstTzInfo 'Asia/Calcutta' IST+5:30:00 STD>>
2019-12-12 12:12:12.000012+05:30 <bound method DstTzInfo.tzname of <DstTzInfo 'Asia/Calcutta' IST+5:30:00 STD>>
2019-12-12 12:12:12.000012+05:53 <bound method DstTzInfo.tzname of <DstTzInfo 'Asia/Calcutta' LMT+5:53:00 STD>>

只要看看时区,就像我在最后一个 d3 对象中所做的那样,每当我尝试使用 tzinfo 传递时区时,您都可以从输出中看到它给我 LMT+5:53 而不是 +5:30 ,但第一个两个日期对象工作正常,帮助我

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com