When I use the date()
function in a Twig template, it returns universal time, as opposed to the date filter which returns the correct time with the proper timezone applied.
I am using
date_default_timezone_set('America/Los_Angeles');
in my theme's functions.php
file for some other non-related functionality, which does appear to directly screw with these dates (when the line of code is removed, the date seems to render correctly). I could use the date_modify
filter, but I'm working with a date between now and the daylight savings time switchover, so it unnecessarily affects what I'm trying to accomplish here.
After reading the Twig docs on the date()
function, I thought the following in my functions.php
file would work, but it doesn't appear to have any affect:
function add_to_twig( $twig ) {
$twig->getExtension(\Twig\Extension\CoreExtension::class)->setTimezone('America/Los_Angeles');
return $twig;
}
So what's the correct way to tell Timber/Twig the timezone to use?