title: Parsing an ISO datetime in Python
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2609259/converting-string-to-datetime-object-in-python">Converting string to datetime object in python</a>  </p>
  </blockquote>
  
  
  
  <p>Given the below Python</p>
  
  <pre><code>import datetime
  
  &gt;&gt;&gt; a
  '2011-05-04 16:20:09 -0700'
  &gt;&gt;&gt; datetime.datetime.strptime(a, "%Y-%m-%d %H:%M:%S %z")
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python2.6/_strptime.py", line 317, in _strptime
      (bad_directive, format))
  ValueError: 'z' is a bad directive in format '%Y-%m-%d %H:%M:%S %z'
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>I don't really understand how <code>%z</code> is a bad directive.</p>
  
  <p>Reference:
  <a href="http://docs.python.org/library/datetime.html#strftime-strptime-behavior" rel="nofollow noreferrer">http://docs.python.org/library/datetime.html#strftime-strptime-behavior</a></p>
  
  <p>This is from hg, which says that it is in ISO8601 format.</p>