date

Converts an argument to a date to allow date comparison:

引数を日付に変換して、日付を比較できるようにします。
1
2
3
{% if date(user.created_at) < date('-2days') %}
    {# do something #}
{% endif %}

The argument must be in one of PHP’s supported date and time formats.

引数は、PHP でサポートされている日付と時刻の形式のいずれかでなければなりません。

You can pass a timezone as the second argument:

2 番目の引数としてタイムゾーンを渡すことができます。
1
2
3
{% if date(user.created_at) < date('-2days', 'Europe/Paris') %}
    {# do something #}
{% endif %}

If no argument is passed, the function returns the current date:

引数が渡されない場合、関数は現在の日付を返します。
1
2
3
{% if date(user.created_at) < date() %}
    {# always! #}
{% endif %}

Note

ノート

You can set the default timezone globally by calling setTimezone() on the core extension instance:

コア拡張インスタンスで setTimezone() を呼び出すことにより、デフォルトのタイムゾーンをグローバルに設定できます。
1
2
$twig = new \Twig\Environment($loader);
$twig->getExtension(\Twig\Extension\CoreExtension::class)->setTimezone('Europe/Paris');

Arguments

  • date: The date
    日付: 日付
  • timezone: The timezone
    timezone: タイムゾーン