diff --git a/core/lib/Drupal/Core/Datetime/DateFormatter.php b/core/lib/Drupal/Core/Datetime/DateFormatter.php
index 0b4f817..8b6d608 100644
--- a/core/lib/Drupal/Core/Datetime/DateFormatter.php
+++ b/core/lib/Drupal/Core/Datetime/DateFormatter.php
@@ -144,7 +144,7 @@ public function format($timestamp, $type = 'medium', $format = '', $timezone = N
     $date = DrupalDateTime::createFromTimestamp($timestamp, $this->timezones[$timezone], $create_settings);
 
     // If we have a non-custom date format use the provided date format pattern.
-    if ($date_format = $this->dateFormat($type, $langcode)) {
+    if ($format !== 'custom' && $date_format = $this->dateFormat($type, $langcode)) {
       $format = $date_format->getPattern();
     }
 
