Contao Date Display Shows Wrong Time Zone on Multilingual Site
0 reputation · 27 Sept 2020, 22:14 UTC
0 reputation · 27 Sept 2020, 22:14 UTC
Ensure that dates rendered in a Contao CMS site appear in the correct regional time zone for each language, while keeping the core configuration stable.
date.timezone setting for its default system offset.date filter, which relies on PHP’s DateTime objects.33275 reputation · 28 Sept 2020, 00:46 UTC
To ensure dates are rendered in the correct regional time zone for different languages in Contao, you must explicitly define the target time zone within the Twig template using the timezone parameter of the date filter. Because Contao does not provide a per-language time zone setting in the admin panel, the application relies on the global PHP date.timezone configuration for all rendered dates by default.
Instead of relying on the server's default offset, pass the desired time zone as the second argument to the date filter. You can map these time zones to your site's language codes:
{# Example: Adjusting timezone based on the current language #}
{% set tz = 'UTC' %}
{% if language == 'de' %}
{% set tz = 'Europe/Berlin' %}
{% elseif language == 'en' %}
{% set tz = 'America/New_York' %}
{% endif %}
{{ date_value|date('d.m.Y H:i', tz) }}
Contao typically stores timestamps in the database as standard date/time strings. The PHP runtime interprets these based on the date.timezone setting in php.ini. When a DateTime object is created in Twig, it inherits this system default. If your server is set to UTC but your users are in Europe, the rendered time will be offset unless a specific time zone is requested during the formatting process.
Global caching (such as Varnish or Cloudflare) can cause "time zone leakage," where a page rendered for a user in one region is cached and served to a user in another. To mitigate this:
Vary: Accept-Language header so the CDN caches separate versions of the page for each language.Intl.DateTimeFormat) to convert the time to the user's local browser time zone.To diagnose the current configuration, run these checks:
echo date_default_timezone_get(); to confirm the active server offset.SELECT NOW(); in your SQL console to see if the database clock matches the system clock.Diagnostic Detail Needed: Are you using a shared hosting environment where you lack access to php.ini, or do you have full control over the PHP-FPM configuration?
Use comments to ask for clarification. Post a solution as an answer.
5,490 reputation · 28 Sept 2020, 00:57 UTC
Contao persists datetime columns as UTC timestamps, but date columns (without time) are stored as plain date strings and are interpreted using the server’s date.timezone when converted to a DateTimeImmutable object. Consequently, when you format a date‑only value with Twig’s date filter you must either cast it to a DateTimeImmutable in the controller or apply the timezone offset manually, e.g. {{ date_value|date('d.m.Y', tz) }} after converting the string to a DateTimeImmutable with new \DateTimeImmutable($date_value, new \DateTimeZone(tz)). This ensures consistent output for both datetime and date‑only fields across languages.