function DateFormatterInterface::formatDiff
Same name in other branches
- 9 core/lib/Drupal/Core/Datetime/DateFormatterInterface.php \Drupal\Core\Datetime\DateFormatterInterface::formatDiff()
- 8.9.x core/lib/Drupal/Core/Datetime/DateFormatterInterface.php \Drupal\Core\Datetime\DateFormatterInterface::formatDiff()
- 11.x core/lib/Drupal/Core/Datetime/DateFormatterInterface.php \Drupal\Core\Datetime\DateFormatterInterface::formatDiff()
Formats a time interval between two timestamps.
Parameters
int $from: A UNIX timestamp, defining the from date and time.
int $to: A UNIX timestamp, defining the to date and time.
array $options: (optional) An associative array with additional options. The following keys can be used:
- granularity: An integer value that signals how many different units to display in the string. Defaults to 2.
- 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.
- strict: A Boolean value indicating whether or not the $from timestamp can be after the $to timestamp. If TRUE (default) and $from is after $to, the result string will be "0 seconds". If FALSE and $from is after $to, the result string will be the formatted time difference.
- return_as_object: A Boolean value whether to return a FormattedDateDiff object.
Return value
string|\Drupal\Core\Datetime\FormattedDateDiff A translated string representation of the interval. This interval is always positive.
See also
\Drupal\Core\Datetime\DateFormatterInterface::formatInterval()
\Drupal\Core\Datetime\DateFormatterInterface::formatTimeDiffSince()
\Drupal\Core\Datetime\DateFormatterInterface::formatTimeDiffUntil()
File
-
core/
lib/ Drupal/ Core/ Datetime/ DateFormatterInterface.php, line 177
Class
- DateFormatterInterface
- Provides an interface defining a date formatter.
Namespace
Drupal\Core\DatetimeCode
public function formatDiff($from, $to, $options = []);
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.