Convert date string to UTC datetime
<p>I returned dates between two given dates:</p>

<pre><code>for date in rrule(DAILY, dtstart = date1, until = date2):
        print date_item.strftime("%Y-%m-%d")
</code></pre>

<p>How to convert the <code>date_item</code> e.g. <code>2016-01-01</code> to ISO 8601 format like:<code>2016-01-01T18:10:18.000Z</code> in python?</p>

<p>I created a sample datetime object like shown below:</p>

<pre><code>from datetime import datetime 
now = datetime.now()
print now
2016-09-21 16:59:18.175038
</code></pre>

<p>Here is the output, formatted to your requirement:</p>

<pre><code>print datetime.strftime(now, "%Y-%m-%dT%H:%M:%S.000Z")
'2016-09-21T16:59:18.000Z'
</code></pre>

<p>Here is a good site to refer the various options, I personally find it easier to use than Python's official docs:
<a href="http://strftime.org" rel="nofollow">http://strftime.org</a></p>

python