Bumped by Community user
    Bumped by Community user
2 added 153 characters in body
source | link

I have a content type with a date field, which I convert to a specific date format in a preprocess function:

$variables['date'] =
\Drupal::service('date.formatter')->format($variables['node']->field_datum->date->getTimestamp(), 'long_date_without_time');

But as Germany is one hour ahead, a date like 2015-03-31 23:01:08 UTC converts to 1. April 2015. How can I convert this to our local time?

EDIT: I already set the correct timezone in the UI. And I just saw that the wrong dates are only shown when I set my system time between 11pm and 1 am...

I have a content type with a date field, which I convert to a specific date format in a preprocess function:

$variables['date'] =
\Drupal::service('date.formatter')->format($variables['node']->field_datum->date->getTimestamp(), 'long_date_without_time');

But as Germany is one hour ahead, a date like 2015-03-31 23:01:08 UTC converts to 1. April 2015. How can I convert this to our local time?

I have a content type with a date field, which I convert to a specific date format in a preprocess function:

$variables['date'] =
\Drupal::service('date.formatter')->format($variables['node']->field_datum->date->getTimestamp(), 'long_date_without_time');

But as Germany is one hour ahead, a date like 2015-03-31 23:01:08 UTC converts to 1. April 2015. How can I convert this to our local time?

EDIT: I already set the correct timezone in the UI. And I just saw that the wrong dates are only shown when I set my system time between 11pm and 1 am...

1
source | link

Convert UTC to local time in date field

I have a content type with a date field, which I convert to a specific date format in a preprocess function:

$variables['date'] =
\Drupal::service('date.formatter')->format($variables['node']->field_datum->date->getTimestamp(), 'long_date_without_time');

But as Germany is one hour ahead, a date like 2015-03-31 23:01:08 UTC converts to 1. April 2015. How can I convert this to our local time?