我如何解析
18 January 2022, 14:50 GMT-5作为时区感知的日期时间。
pytz.timezone('GMT-5')失败了。看来我可能需要解析GMT部分,并手动应用5小时偏移后解析?
发布于 2022-01-18 21:49:51
嗯,也许:
import re
import datetime
foo = "18 January 2022, 14:50 GMT-5"
bar = re.sub(r"[+-]\d+$", lambda m: "{:05d}".format(100 * int(m.group())), foo)
print(datetime.datetime.strptime(bar, "%d %B %Y, %H:%M %Z%z" ))我想这会让你:
2022-01-18 14:50:00-05:00
https://stackoverflow.com/questions/70761886
复制相似问题