Bundle provides simple and easy to use Twig filter m_datetime
. By default it will use date format specified by given siteaccess locale.
{{ ez_field_value(content, 'my_date').date|m_datetime }}
Which will format date by IntlDateFormatter::SHORT
format by default, or by any of this listed
constants
in case any of them is specified in overridden config.
{{ ez_field_value(content, 'my_date').date|m_datetime('my_custom_format') }}
Will format date by my_custom_format
which must be specified in configuration.
eZ Platform Twig statements:
{{ ez_field_value(content, 'my_date').date|m_datetime }}
{{ ez_field_value(content, 'my_date').date|m_datetime('my_custom_format') }}
In case of Netgen's Site API:
{{ content.fields.my_date.value.date|m_datetime }}
{{ content.fields.my_date.value.date|m_datetime('my_custom_format') }}
eZ Platform Twig statements:
{{ ez_field_value(content, 'my_date').value|m_datetime }}
{{ ez_field_value(content, 'my_date').value|m_datetime('my_custom_format') }}
In case of Netgen's Site API:
{{ content.fields.my_date.value.value|m_datetime }}
{{ content.fields.my_date.value.value|m_datetime('my_custom_format') }}
As default format IntlDateFormatter::SHORT
is presumed, but other values can be set under defaults format configuration key.
This example config overrides default format for eng
siteaccess and sets format to IntlDateFormatter::LONG
, defines two custom formats for eng
siteaccess and one custom format for default
.
Example configuration in ezplatform.yml
:
marek_site_access_aware_date_format:
system:
eng:
defaults:
format: 'long'
formats:
long_date: "y.m.d"
my_custom_format: "y.m."
default:
formats:
my_custom_format: "Y"
Under formats
section, any valid format character from documentation can be specified.