Flask response should display mongodb last-modified date in ISO format
<p>I'm using flask to create API. My database is mongodb.</p>

<p>When flask response come, the last modified date is coming in the following format.</p>

<pre><code>"lastModified": {"$date": 1473929954742}
</code></pre>

<p>I'm using Pycharm as IDE on the Pycharm Run terminal is showing in the following format</p>

<pre><code>"lastModified": {"$date": 1473929954742}
</code></pre>

<p>In Mongodb shell showing the following format</p>

<pre><code>"lastModified" : ISODate("2016-09-15T08:59:14.742Z")
</code></pre>

<p>How to show the date in the format which contains in Mongodb when flask response come.</p>

<p>I have used the following line inside flask to return the response.</p>

<pre><code>return json.dumps(alldata, default=json_util.default)
</code></pre>

<p>Please help me.</p>

<p>Thanks</p>

<p>If you want to convert the timestamp to a ISO formatted date, you can use <code>utcfromtimestamp</code>.</p>

<pre><code>import datetime as dt
timestamp = 1473929954742/1000
print dt.datetime.utcfromtimestamp(timestamp).isoformat()
# '2016-09-15T08:59:14'
</code></pre>

python mongodb python-2.7 flask