擅长:python、mysql、java
<p>自从Django 1.11以来,您可以简单地调用<a href="https://docs.djangoproject.com/en/2.0/ref/utils/#django.utils.timezone.localtime" rel="noreferrer">^{<cd1>}</a>来获取默认时区的<code>datetime</code>。</p>
<pre><code>>>> from django.utils import timezone
>>> timezone.localtime()
</code></pre>
<p>来自文档:</p>
<blockquote>
<p>Converts an aware datetime to a different time zone, by default the current time zone.</p>
<p>When value is omitted, it defaults to <a href="http://django.utils.timezone.localtime](https://docs.djangoproject.com/en/2.0/ref/utils/#django.utils.timezone.now" rel="noreferrer"><code>now()</code></a>.</p>
<p>This function doesn’t work on naive datetimes; use <a href="https://docs.djangoproject.com/en/2.0/ref/utils/#django.utils.timezone.make_aware" rel="noreferrer"><code>make_aware()</code></a> instead.</p>
</blockquote>