Skip to content

Instantly share code, notes, and snippets.

@midnai
Created February 19, 2018 15:53
Show Gist options
  • Save midnai/db93d1aaa93121564460a443b9ad77b8 to your computer and use it in GitHub Desktop.
Save midnai/db93d1aaa93121564460a443b9ad77b8 to your computer and use it in GitHub Desktop.
Drupal 8 - Format a timestamp to a custom format
public function formatDate($date)
{
$date = new \DateTime($date);
$date = $date->getTimestamp();
return \Drupal::service('date.formatter')->format($date, '', 'd \d\e F \d\e Y');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment