1

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?

Roman Bodnarchuk
  • 29,461
  • 12
  • 59
  • 75
Will
  • 73,905
  • 40
  • 169
  • 246
  • See http://stackoverflow.com/questions/4458705/flexible-english-date-phrase-library-for-python – gimel Jul 04 '11 at 12:31
  • related: [Convert timestamps with offset to datetime obj using strptime](http://stackoverflow.com/q/12281975/4279) – jfs Jan 08 '15 at 07:27

1 Answers1

8

Try using dateutil.

from dateutil.parser import parse    
dt = parse("2011-06-27 10:29:56+0200")
Paul
  • 10,381
  • 13
  • 48
  • 86
thomson_matt
  • 7,473
  • 3
  • 39
  • 47