Skip to content

Commit

Permalink
Tweak docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 25, 2022
1 parent c17b0af commit 3178098
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions doc/filters/format_datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ The ``format_datetime`` filter formats a date time:
{# Aug 7, 2019, 11:39:12 PM #}
{{ '2019-08-07 23:39:12'|format_datetime() }}
Format
------

You can tweak the output for the date part and the time part:

.. code-block:: twig
Expand All @@ -27,46 +30,34 @@ You can tweak the output for the date part and the time part:
Supported values are: ``none``, ``short``, ``medium``, ``long``, and ``full``.

For greater flexibility, you can even define your own pattern (see the `ICU user
guide
<https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax>`_
for supported patterns).
For greater flexibility, you can even define your own pattern (see the `ICU
user guide`_ for supported patterns).

.. code-block:: twig
{# 11 oclock PM, GMT #}
{{ '2019-08-07 23:39:12'|format_datetime(pattern="hh 'oclock' a, zzzz") }}
Locale
------

By default, the filter uses the current locale. You can pass it explicitly:

.. code-block:: twig
{# 7 août 2019 23:39:12 #}
{{ '2019-08-07 23:39:12'|format_datetime(locale='fr') }}
It is possible to set TimeZone (see `WiKi: List of tz database time zones
<https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>`_
). Date and time for timezone set via argument calculated from default timezone, default timezone depends from `system settings
<https://twig.symfony.com/doc/1.x/filters/date.html#timezone>`_
.

.. code-block:: twig
{% set datetime='2020-02-02 13:15:00' %}
{% set pattern='MMM d (eee) HH:mm (v / ZZZZ)' %}
{# Current default timezone `Europe/Moscow` GMT+3 #}
{# Feb 2 (Sun) 13:15 (Moscow Time / GMT+03:00) #}
{{ datetime|format_datetime(locale='en', pattern=pattern) }}
Timezone
--------

{# -11:00 - 3:00 | -14:00 #}
{# Feb 1 (Sat) 23:15 (Midway Time / GMT-11:00) #}
{{ datetime|format_datetime(locale='en', pattern=pattern, timezone='Pacific/Midway') }}
By default, the date is displayed by applying the default timezone (the one
specified in php.ini), but you can override it by explicitly specifying a
timezone:

{# 13:45 - 3:00 | +10:45 #}
{# Feb 3 (Mon) 00:00 (Chatham Time / GMT+13:45) #}
{{ datetime|format_datetime(locale='en', pattern=pattern, timezone='Pacific/Chatham') }}
.. code-block:: twig
{{ datetime|format_datetime(locale='en', timezone='Pacific/Midway') }}
.. note::

Expand Down Expand Up @@ -99,3 +90,5 @@ Arguments
* ``pattern``: A date time pattern
* ``timezone``: The date timezone name
* ``calendar``: The calendar (Gregorian by default)

.. _ICU user guide: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax

0 comments on commit 3178098

Please sign in to comment.