擅长:python、mysql、java
<p>在模板中,已经有一个内置函数<a href="https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#now" rel="nofollow">^{<cd1>}</a>:</p>
<blockquote>
<p>Displays the current date and/or time, using a format according to the
given string. Such string can contain format specifiers characters as
described in the date filter section.</p>
<p>Example:</p>
<pre><code>It is {% now "jS F Y H:i" %}
</code></pre>
</blockquote>
<p>在django<strong>1.8</strong>中,您可以将它与<code>as</code>一起使用:</p>
<pre><code>{% now "Y" as current_year %}
{% blocktrans %}Copyright {{ current_year }}{% endblocktrans %}
</code></pre>
<hr/>
<p>在python代码中,日期没有django内置,只需使用python<code>datetime.date.now()</code>来创建自己的自定义函数。</p>