Format created date of custom entity in drupal 8 [Solved]

Some parts of custom entities seem different from nodes, but mostly they aren't. Small snippet for showing a created date of a custom entity in a controller.

$timestamp = $entity->get('created')->first()->getValue();
$formatted_date = date('j M Y', $timestamp['value']);

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!