开发者

python parsing a datetime with a timezone [duplicate]

开发者 https://www.devze.com 2023-03-17 16:34 出处:网络
This question already has answers here: Python time to age, part 2: timezones [duplicate] (5 answers) Closed 7 years ago.
This question already has answers here: Python time to age, part 2: timezones [duplicate] (5 answers) Closed 7 years ago.

I am trying to parse an string from a log file in the format: 开发者_如何学JAVA2011-06-27 10:29:56+0200

If I use datetime.datetime.strptime('%Y-%m-%d %H:%M:%S%z') I get ValueError("'z' is a bad directive in format '%Y-%m-%d %H:%M:%S%z'") thrown

How can I parse a date in this format?


Try using dateutil.

from dateutil.parser import parse    
dt = parse("2011-06-27 10:29:56+0200")
0

精彩评论

暂无评论...
验证码 换一张
取 消