【发布时间】:2021-01-22 00:13:18
【问题描述】:
所以我有 -
timezone = pytz.timezone('Asia/Kolkata')
one_time_stamp = '2017-06-01 05:30:00'
zoned_time_stamp = datetime.datetime.strptime(one_time_stamp, '%Y-%m-%d %H:%M:%S')
#This outputs 2017-06-01 05:30:00 which is fine.
print(zoned_time_stamp)
#notice timezone added
non_iso_zoned_ts = zoned_time_stamp.replace(microsecond=0, tzinfo=timezone)
# This outputs 2017-06-01 05:30:00 which is fine.
print(zoned_time_stamp)
iso_date = non_iso_zoned_ts.isoformat()
#This outputs 2017-06-01T05:30:00+05:53 which is incorrect. Ideally it should be 2017-06-01T05:30:00+05:30
print(iso_date)
现在我想知道为什么 isoformat 添加 05:53 的偏移量,而亚洲/加尔各答时区是 +05:30。参考 - https://www.zeitverschiebung.net/en/timezone/asia--kolkata
【问题讨论】:
-
考虑使用dateutil 或zoneinfo (Python 3.9)。 pytzwill be deprecated.
-
相关:stackoverflow.com/questions/64237932/…(SO 上有 许多 更多...)。
标签: python python-datetime pytz