diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php
index 4511346..213bccc 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php
@@ -94,8 +94,6 @@ function testAdminDefinedFormatDate() {
    * Tests the format_date() function.
    */
   function testFormatDate() {
-    global $user;
-
     $language_interface = language(Language::TYPE_INTERFACE);

     $timestamp = strtotime('2007-03-26T00:00:00+00:00');
@@ -127,11 +125,13 @@ function testFormatDate() {
     $edit = array('preferred_langcode' => self::LANGCODE, 'mail' => $test_user->getEmail(), 'timezone' => 'America/Los_Angeles');
     $this->drupalPostForm('user/' . $test_user->id() . '/edit', $edit, t('Save'));

-    // Disable session saving as we are about to modify the global $user.
+    // Disable session saving as we are about to modify the current user.
     drupal_save_session(FALSE);
     // Save the original user and language and then replace it with the test user and language.
-    $real_user = $user;
+    $real_user = \Drupal::currentUser();
     $user = user_load($test_user->id(), TRUE);
+    \Drupal::getContainer()->set('current_user', $user);
+
     $real_language = $language_interface->id;
     $language_interface->id = $user->getPreferredLangcode();
     // Simulate a Drupal bootstrap with the logged-in user.
@@ -154,7 +154,7 @@ function testFormatDate() {
     $this->assertIdentical(format_date($timestamp, 'html_year'), '2007', 'Test html_year date format.');

     // Restore the original user and language, and enable session saving.
-    $user = $real_user;
+    \Drupal::getContainer()->set('current_user', $real_user);
     $language_interface->id = $real_language;
     // Restore default time zone.
     date_default_timezone_set(drupal_get_user_timezone());
