Skip to main content
 首页 » 编程设计

python之如何让 python datetime.strptime 考虑传递的时区

2025年02月15日10bonelee

<分区>

尝试将字符串转换为 datetime 并将其保存到 db。该字符串指定时区,但 strptime 不接受 %z 选项。

datetime.strptime("Tue Feb 14 2017 15:30:01 GMT-0500", "%a %b %d %Y %H:%M:%S GMT%z") 

ValueError: 'z' is a bad directive in format '%a %b %d %Y %H:%M:%S GMT%z'