Convert custom strings to datetime format
<p>I have a list of date-time data strings that looks like this:</p>

<pre><code>list = ["2016-08-02T09:20:32.456Z", "2016-07-03T09:22:35.129Z"]
</code></pre>

<p>I want to convert this to the example format (for the first item):</p>

<pre><code>"8/2/2016 9:20:32 AM"
</code></pre>

<p>I tried this:</p>

<pre><code>from datetime import datetime
for time in list:
    date = datetime.strptime(time, '%Y %m %d %I %R')
</code></pre>

<p>But returns error:</p>

<blockquote>
  <p>ValueError: 'R' is a bad directive in format '%Y %m %d %I %R'</p>
</blockquote>

<p>Thanks for any help!</p>

<pre><code>s = "2016-08-02T09:20:32.456Z"
d = datetime.strptime(s, "%Y-%m-%dT%H:%M:%S.%fZ")
</code></pre>

<p>The use <code>d.strftime</code> (<a href="https://docs.python.org/3.0/library/datetime.html#id1" rel="nofollow">https://docs.python.org/3.0/library/datetime.html#id1</a>).</p>

python date converter