You are here

public function DateFormatterInterface::formatInterval in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Datetime/DateFormatterInterface.php \Drupal\Core\Datetime\DateFormatterInterface::formatInterval()
  2. 9 core/lib/Drupal/Core/Datetime/DateFormatterInterface.php \Drupal\Core\Datetime\DateFormatterInterface::formatInterval()

Formats a time interval with the requested granularity.

Note that for intervals over 30 days, the output is approximate: a "month" is always exactly 30 days, and a "year" is always 365 days. It is not possible to make a more exact representation, given that there is only one input in seconds. If you are formatting an interval between two specific timestamps, use \Drupal\Core\Datetime\DateFormatter::formatDiff() instead.

Parameters

int $interval: The length of the interval in seconds.

int $granularity: (optional) How many different units to display in the string (2 by default).

string|null $langcode: (optional) langcode: The language code for the language used to format the date. Defaults to NULL, which results in the user interface language for the page being used.

Return value

string A translated string representation of the interval.

See also

\Drupal\Core\Datetime\DateFormatterInterface::formatDiff()

File

core/lib/Drupal/Core/Datetime/DateFormatterInterface.php, line 66

Class

DateFormatterInterface
Provides an interface defining a date formatter.

Namespace

Drupal\Core\Datetime

Code

public function formatInterval($interval, $granularity = 2, $langcode = NULL);