Example of using this with a date field from a node in order to get it to format the date in the correct timezone
User login
Friday, May 29, 2020 - 13:12
use Drupal\Core\Datetime\DrupalDateTime; $date = new DrupalDateTime($mynode->field_my_date_field->value, 'UTC'); $formatted_date = \Drupal::service('date.formatter')->format($date->getTimestamp(), 'custom', 'F j, Y h:ia');
Tags:
Drupal 8