问题
I am trying to parse an string from a log file in the format: 2011-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?
回答1:
Try using dateutil.
from dateutil.parser import parse
dt = parse("2011-06-27 10:29:56+0200")
来源:https://stackoverflow.com/questions/6571419/python-parsing-a-datetime-with-a-timezone