python使用时区解析日期时间

Wil*_*ill 1 python time date

我试图以下面的格式解析日志文件中的字符串: 2011-06-27 10:29:56+0200

如果我使用datetime.datetime.strptime('%Y-%m-%d %H:%M:%S%z')我会ValueError("'z' is a bad directive in format '%Y-%m-%d %H:%M:%S%z'")被抛出

如何以这种格式解析日期?

tho*_*att 8

尝试使用dateutil.

from dateutil.parser import parse    
dt = parse("2011-06-27 10:29:56+0200")
Run Code Online (Sandbox Code Playgroud)