【发布时间】:2020-09-22 14:55:29
【问题描述】:
将字符串 'GMT+5:30' 转换为时区(如 Aisa/Kolkata)而不在 python 中检查 datetime.datetime.now()
now = datetime.datetime.astimezone(Time_Zone).tzname() # current time
print(now)
print(type(now))
utc_offset = datetime.timedelta(hours=5, minutes=30) # +5:30
print(utc_offset)
for tz in map(pytz.timezone, pytz.all_timezones_set):
if (now.astimezone(tz).utcoffset() == utc_offset):
print(tz.zone)
【问题讨论】:
-
代码有问题吗?它会抛出任何错误吗?