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>python datetime can't parse the <code>GMT</code> part (You might want to specify it manually in your format). You can use <code>dateutil</code> instead:</p>

<pre><code>In [16]: s = 'Tue Oct 04 2016 12:13:00 GMT+0200 (CEST)'

In [17]: from dateutil import parser

In [18]: parser.parse(s)
Out[18]: d = datetime.datetime(2016, 10, 4, 12, 13, tzinfo=tzoffset(u'CEST', -7200))
In [30]: d.utcoffset()
Out[30]: datetime.timedelta(-1, 79200)

In [31]: d.tzname()
Out[31]: 'CEST'
</code></pre>

python date