How to convert string date with timezone to datetime?
<p>I have date in string:</p>

<pre><code>Tue Oct 04 2016 12:13:00 GMT+0200 (CEST)
</code></pre>

<p>and I use (according to <a href="https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior" rel="nofollow">https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior</a>):</p>

<pre><code>datetime.strptime(datetime_string, '%a %b %m %Y %H:%M:%S %z %Z')
</code></pre>

<p>but I get error:</p>

<pre><code>ValueError: 'z' is a bad directive in format '%a %b %m %Y %H:%M:%S %z %Z'
</code></pre>

<p>How to do it correctly?</p>

<p>Simpler way to achieve this without taking care of <code>datetime</code> formatting identifiers will be the usage of <a href="http://dateutil.readthedocs.io/en/latest/parser.html" rel="nofollow"><code>dateutil.parser()</code></a>. For example:</p>

<pre><code>&gt;&gt;&gt; import dateutil.parser 
&gt;&gt;&gt; date_string = 'Tue Oct 04 2016 12:13:00 GMT+0200 (CEST)'
&gt;&gt;&gt; dateutil.parser.parse(date_string)
datetime.datetime(2016, 10, 4, 12, 13, tzinfo=tzoffset(u'CEST', -7200))
</code></pre>

python date