Skip to content

Instantly share code, notes, and snippets.

@zerolab
Created February 21, 2017 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerolab/09f8086ddc324ac220bb943b2716e0c6 to your computer and use it in GitHub Desktop.
Save zerolab/09f8086ddc324ac220bb943b2716e0c6 to your computer and use it in GitHub Desktop.
A set of Drupal 8 snippets
<?php
// if you have an account object ($user), then you can use $user->getTimezone().
$timezone = \Drupal::currentUser()->getTimezone();
$given = new \Drupal\Core\Datetime\DrupalDateTime("2016-08-01T12:30:00", $timezone);
$given->setTimezone(new \DateTimeZone("UTC"));
print $given->format("Y-m-d\Th:i:s");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment