Tweak docs

This commit is contained in:
Fabien Potencier
2022-03-25 09:48:05 +01:00
parent c17b0af03e
commit 3178098337
+17 -24
View File
@@ -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
@@ -27,16 +30,17 @@ 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
@@ -44,29 +48,16 @@ By default, the filter uses the current locale. You can pass it explicitly:
{# 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>`_
.
Timezone
--------
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:
.. 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) }}
{# -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') }}
{# 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') }}
{{ datetime|format_datetime(locale='en', timezone='Pacific/Midway') }}
.. note::
@@ -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