ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# `date` New in version 1.6: The date function has been added in Twig 1.6. New in version 1.6.1: The default timezone support has been added in Twig 1.6.1. Converts an argument to a date to allow date comparison: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2 3</pre></div></td><td class="code"><div class="highlight"><pre>{% if date(user.created_at) &lt; date('-2days') %} {# do something #} {% endif %} </pre></div></td></tr></table> The argument must be in one of PHP鈥檚 supported [date and time formats](http://php.net/manual/en/datetime.formats.php) [http://php.net/manual/en/datetime.formats.php]. You can pass a timezone as the second argument: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2 3</pre></div></td><td class="code"><div class="highlight"><pre>{% if date(user.created_at) &lt; date('-2days', 'Europe/Paris') %} {# do something #} {% endif %} </pre></div></td></tr></table> If no argument is passed, the function returns the current date: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2 3</pre></div></td><td class="code"><div class="highlight"><pre>{% if date(user.created_at) &lt; date() %} {# always! #} {% endif %} </pre></div></td></tr></table> Note You can set the default timezone globally by calling `setTimezone()` onthe `core` extension instance: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2</pre></div></td><td class="code"><div class="highlight"><pre>$twig = new Twig_Environment($loader); $twig-&gt;getExtension('core')-&gt;setTimezone('Europe/Paris'); </pre></div></td></tr></table> ### Arguments - `date`: The date - `timezone`: The timezone