Wrong time value in a date field I've got a Date field in Drupal that I want to preprocess. Unfortunately

$node-&gt;field_date_time-&gt;value;


Gives me a value off by one hour (8:00 when expected is 9:00). I believe the issue has something to do with the way Drupal stores the date vs how it displays it later (taking into account Timezones). I tried passing in the default timezone to the DateTime object but that didn't help. I also tried using the \Drupal::service('date.formatter') to format the date but the result is still off.

When debugging I found that by using:

$node-&gt;field_date_time-&gt;date


I can see the expected date under a protected DateTimeObject property (see screenshot).


Does anyone know how to extract it or maybe there's something else that I'm missing? I'm running Drupal 8.1.9
When displaying a date field, Drupal typically converts it to the timezone of the currently logged in user. If no user is logged in, the site's default timezone is used. Perhaps you're logged in as a user that has a different timezone set?

Also, note that the time is internally stored as UTC, so you'll see a time that is off by an hour when simply printing the date's value or using a debugger. If you want to print the time in the user's timezone, try something like:

\Drupal::service('date.formatter')-&gt;format($date-&gt;getTimestamp());


This will use the user's timezone, or fall back to the site's default timezone.