diff --git a/core/lib/Drupal/Core/Datetime/DateFormatter.php b/core/lib/Drupal/Core/Datetime/DateFormatter.php
index fd445e3..db8e6bf 100644
--- a/core/lib/Drupal/Core/Datetime/DateFormatter.php
+++ b/core/lib/Drupal/Core/Datetime/DateFormatter.php
@@ -130,7 +130,7 @@ public function __construct(EntityManagerInterface $entity_manager, LanguageMana
    *   (optional) Language code to translate to. NULL (default) means to use
    *   the user interface language for the page.
    *
-   * @return string
+   * @return \Drupal\Core\Datetime\DateString
    *   A translated date string in the requested format.
    */
   public function format($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
@@ -168,7 +168,7 @@ public function format($timestamp, $type = 'medium', $format = '', $timezone = N
     $settings = array(
       'langcode' => $langcode,
     );
-    return Xss::filter($date->format($format, $settings));
+    return $date->format($format, $settings);
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Datetime/DateString.php b/core/lib/Drupal/Core/Datetime/DateString.php
new file mode 100644
index 0000000..cf21c73
--- /dev/null
+++ b/core/lib/Drupal/Core/Datetime/DateString.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Datetime\DateString.
+ */
+
+namespace Drupal\Core\Datetime;
+
+use Drupal\Component\Utility\SafeStringInterface;
+use Drupal\Component\Utility\SafeStringTrait;
+use Drupal\Component\Utility\Xss;
+
+/**
+ * Defines an object that contains a formatted date.
+ *
+ * This object should only be constructed by the date formatter.
+ *
+ * @internal
+ *   This object is marked as internal because it should only be used by the
+ *   date formatter to return formatted dates.
+ *
+ * @see \Drupal\Core\Template\TwigExtension::escapeFilter
+ * @see \Twig_Markup
+ * @see \Drupal\Core\Datetime\DateFormatter::format
+ */
+final class DateString implements SafeStringInterface, \Countable {
+  use SafeStringTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __toString() {
+    return Xss::filter($this->string);
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php
index e7c71f1..68f46da 100644
--- a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php
+++ b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php
@@ -89,8 +89,8 @@ protected function prepareTimezone($timezone) {
    *   - langcode: (optional) String two letter language code used to control
    *     the result of the format() method. Defaults to NULL.
    *
-   * @return string
-   *   The formatted value of the date.
+   * @return \Drupal\Core\Datetime\DateString
+   *   A date string in the requested format.
    */
   public function format($format, $settings = array()) {
     $langcode = !empty($settings['langcode']) ? $settings['langcode'] : $this->langcode;
@@ -134,7 +134,7 @@ public function format($format, $settings = array()) {
     catch (\Exception $e) {
       $this->errors[] = $e->getMessage();
     }
-    return $value;
+    return DateString::create($value);
   }
 
 }
diff --git a/core/lib/Drupal/Core/Datetime/Element/Datetime.php b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
index f9ccb45..3eb7c84 100644
--- a/core/lib/Drupal/Core/Datetime/Element/Datetime.php
+++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
@@ -241,7 +241,7 @@ public static function processDatetime(&$element, FormStateInterface $form_state
       // placeholders are invalid for HTML5 date and datetime, so an example
       // format is appended to the title to appear in tooltips.
       $extra_attributes = array(
-        'title' => t('Date (e.g. !format)', array('!format' => static::formatExample($date_format))),
+        'title' => t('Date (e.g. @format)', array('@format' => static::formatExample($date_format))),
         'type' => $element['#date_date_element'],
       );
 
@@ -288,7 +288,7 @@ public static function processDatetime(&$element, FormStateInterface $form_state
 
       // Adds the HTML5 attributes.
       $extra_attributes = array(
-        'title' => t('Time (e.g. !format)', array('!format' => static::formatExample($time_format))),
+        'title' => t('Time (e.g. @format)', array('@format' => static::formatExample($time_format))),
         'type' => $element['#date_time_element'],
         'step' => $element['#date_increment'],
       );
diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php
index fef4c32..45ecf53 100644
--- a/core/lib/Drupal/Core/Extension/module.api.php
+++ b/core/lib/Drupal/Core/Extension/module.api.php
@@ -946,7 +946,7 @@ function hook_requirements($phase) {
     $cron_last = \Drupal::state()->get('system.cron_last');
 
     if (is_numeric($cron_last)) {
-      $requirements['cron']['value'] = t('Last run !time ago', array('!time' => \Drupal::service('date.formatter')->formatTimeDiffSince($cron_last)));
+      $requirements['cron']['value'] = t('Last run @time ago', array('@time' => \Drupal::service('date.formatter')->formatTimeDiffSince($cron_last)));
     }
     else {
       $requirements['cron'] = array(
diff --git a/core/modules/system/src/Tests/System/DateTimeTest.php b/core/modules/system/src/Tests/System/DateTimeTest.php
index 39dac52..517ac13 100644
--- a/core/modules/system/src/Tests/System/DateTimeTest.php
+++ b/core/modules/system/src/Tests/System/DateTimeTest.php
@@ -133,6 +133,21 @@ function testDateFormatConfiguration() {
     $this->assertText(t('Custom date format added.'), 'Date format added confirmation message appears.');
     $this->assertText($name, 'Custom date format appears in the date format list.');
     $this->assertText(t('Delete'), 'Delete link for custom date format appears.');
+
+    // Add a new date format with HTML in it.
+    $date_format_id = strtolower($this->randomMachineName(8));
+    $name = ucwords($date_format_id);
+    $date_format = '& \<\e\m\>Y\<\/\e\m\>';
+    $edit = array(
+      'id' => $date_format_id,
+      'label' => $name,
+      'date_format_pattern' => $date_format,
+    );
+    $this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
+    $this->assertUrl(\Drupal::url('entity.date_format.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
+    $this->assertText(t('Custom date format added.'), 'Date format added confirmation message appears.');
+    $this->assertText($name, 'Custom date format appears in the date format list.');
+    $this->assertRaw('&amp; <em>' . date("Y") . '</em>');
   }
 
   /**
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index c168b24..563a119 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -464,7 +464,7 @@ function system_requirements($phase) {
     }
 
     // Set summary and description based on values determined above.
-    $summary = t('Last run !time ago', array('!time' => \Drupal::service('date.formatter')->formatTimeDiffSince($cron_last)));
+    $summary = t('Last run @time ago', array('@time' => \Drupal::service('date.formatter')->formatTimeDiffSince($cron_last)));
 
     $requirements['cron'] = array(
       'title' => t('Cron maintenance tasks'),
diff --git a/core/modules/tracker/tracker.pages.inc b/core/modules/tracker/tracker.pages.inc
index 47bd3ef..68c0667 100644
--- a/core/modules/tracker/tracker.pages.inc
+++ b/core/modules/tracker/tracker.pages.inc
@@ -106,8 +106,8 @@ function tracker_page($account = NULL) {
           'data-history-node-last-comment-timestamp' => $node->last_comment_timestamp,
         ),
         'last updated' => array(
-          'data' => t('!time ago', array(
-            '!time' => \Drupal::service('date.formatter')->formatTimeDiffSince($node->last_activity),
+          'data' => t('@time ago', array(
+            '@time' => \Drupal::service('date.formatter')->formatTimeDiffSince($node->last_activity),
           )),
         ),
       );
diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php
index 1b335de..cad9be5 100644
--- a/core/modules/views_ui/src/ViewEditForm.php
+++ b/core/modules/views_ui/src/ViewEditForm.php
@@ -140,13 +140,13 @@ public function form(array $form, FormStateInterface $form_state) {
       );
       $lock_message_substitutions = array(
         '!user' => drupal_render($username),
-        '!age' => $this->dateFormatter->formatTimeDiffSince($view->lock->updated),
+        '@age' => $this->dateFormatter->formatTimeDiffSince($view->lock->updated),
         '@url' => $view->url('break-lock-form'),
       );
       $form['locked'] = array(
         '#type' => 'container',
         '#attributes' => array('class' => array('view-locked', 'messages', 'messages--warning')),
-        '#children' => $this->t('This view is being edited by user !user, and is therefore locked from editing by others. This lock is !age old. Click here to <a href="@url">break this lock</a>.', $lock_message_substitutions),
+        '#children' => $this->t('This view is being edited by user !user, and is therefore locked from editing by others. This lock is @age old. Click here to <a href="@url">break this lock</a>.', $lock_message_substitutions),
         '#weight' => -10,
       );
     }
