Custom version of DateFormatter service
The full story can be found at Altering existing services, providing dynamic services, but essentially you need to add a service provider to your module, e.g. (mostly copied from the d.o page above):

namespace Drupal\my_module;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;

/**
 * Modifies the date formatter service.
 */
class MyModuleServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    // Overrides date.formatter class for custom interval formatting.
    $definition = $container-&gt;getDefinition('date.formatter');
    $definition-&gt;setClass(DateFormatter::class);
  }
}


(assuming your replacement class is \Drupal\my_module\DateFormatter)