DateFormatterInterface::formatInterval

public DateFormatterInterface::formatInterval($interval, $granularity = 2, $langcode = NULL)

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);
doc_Drupal
2016-10-29 09:00:47
Comments
Leave a Comment

Please login to continue.