Untitled
unknown
plain_text
6 months ago
694 B
3
Indexable
function mytheme_preprocess_page(&$variables) { // Check if this is a node page and specifically of content type "meeting". if (isset($variables['node']) && $variables['node']->getType() === 'meeting') { if (!empty($variables['node']->field_when->value)) { // Convert the date and set the time zone. $date = new \DateTime($variables['node']->field_when->value, new \DateTimeZone('UTC')); $user_timezone = \Drupal::currentUser()->getTimeZone() ?: 'Europe/Zurich'; $date->setTimezone(new \DateTimeZone($user_timezone)); // Add the formatted date to the template variables. $variables['formatted_when'] = $date->format('Y-m-d H:i:s'); } } }
Editor is loading...
Leave a Comment