mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-10 09:26:29 +00:00
updated doc for the date filter
This commit is contained in:
+10
-7
@@ -13,9 +13,9 @@ The ``date`` filter formats a date to a given format:
|
||||
|
||||
{{ post.published_at|date("m/d/Y") }}
|
||||
|
||||
The ``date`` filter accepts any date format supported by `date`_ and
|
||||
`DateTime`_ instances. For instance, to display the current date, filter the
|
||||
word "now":
|
||||
The ``date`` filter accepts strings (it must be in a format supported by the
|
||||
`date`_ function), `DateTime`_ instances, or `DateInterval`_ instances. For
|
||||
instance, to display the current date, filter the word "now":
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
@@ -34,12 +34,15 @@ You can also specify a timezone:
|
||||
{{ post.published_at|date("m/d/Y", "Europe/Paris") }}
|
||||
|
||||
If no format is provided, Twig will use the default one: ``F j, Y H:i``. This
|
||||
default can be easily changed:
|
||||
default can be easily changed by calling the `setDateFormat()` method on the
|
||||
`core` extension instance. The first argument is the default format for dates
|
||||
and the second one is the default format for date intervals:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$twig = new Twig_Environment($loader);
|
||||
$twig->getExtension('core')->setDateFormat('d/m/Y');
|
||||
$twig->getExtension('core')->setDateFormat('d/m/Y', '%d days');
|
||||
|
||||
.. _`date`: http://www.php.net/date
|
||||
.. _`DateTime`: http://www.php.net/manual/en/datetime.construct.php
|
||||
.. _`date`: http://www.php.net/date
|
||||
.. _`DateTime`: http://www.php.net/DateTime
|
||||
.. _`DateInterval`: http://www.php.net/DateInterval
|
||||
|
||||
Reference in New Issue
Block a user