updated doc for the date filter

This commit is contained in:
Fabien Potencier
2011-12-30 09:21:01 +01:00
parent 736dfa84d0
commit f64d976182
+10 -7
View File
@@ -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