Datetime object with timezone
<p>How do I get an aware datetime object using the modified timestamp from a file? I've done it this way:</p>

<pre><code>modified = datetime.datetime.fromtimestamp(os.path.getmtime(myfile))
isotime = modified.strftime('%Y-%m-%d %H:%M:%S %z')
</code></pre>

<p>but this just gets me a naive time, so %z is a blank string like: 2016-09-03 10:35:24</p>

<p>I've been using this documentation, but I can't understand how to make a tzinfo object for the system timezone: <a href="https://docs.python.org/2/library/datetime.html" rel="nofollow">https://docs.python.org/2/library/datetime.html</a></p>

<p>It is pain in the ass to get the current time zone using python standart library.</p>

<p>Just install <a href="https://dateutil.readthedocs.io/en/stable/tz.html" rel="nofollow"><code>dateutil</code></a> package:</p>

<pre><code>$ sudo pip install python-dateutil
</code></pre>

<p>and you can do the following:</p>

<p>--</p>

<pre><code>&gt;&gt;&gt; from dateutil.tz import tzlocal
&gt;&gt;&gt; datetime.datetime.fromtimestamp(os.path.getmtime("file"), tz=tzlocal())
</code></pre>

python datetime