i18n\Formatter asRelativeTime()

asRelativeTime() public method

Formats the value as the time interval between a date and now in human readable form.

This method can be used in three different ways:

  1. Using a timestamp that is relative to now.
  2. Using a timestamp that is relative to the $referenceTime.
  3. Using a DateInterval object.
public string asRelativeTime ( $value, $referenceTime = null )
$value integer|string|DateTime|DateInterval

The value to be formatted. The following types of value are supported:

  • an integer representing a UNIX timestamp
  • a string that can be parsed to create a DateTime object. The timestamp is assumed to be in $defaultTimeZone unless a time zone is explicitly given.
  • a PHP DateTime object
  • a PHP DateInterval object (a positive time interval will refer to the past, a negative one to the future)
$referenceTime integer|string|DateTime

If specified the value is used as a reference time instead of now when $value is not a DateInterval object.

return string

The formatted result.

throws yii\base\InvalidParamException

if the input value can not be evaluated as a date value.

doc_Yii
2016-10-30 17:06:01
Comments
Leave a Comment

Please login to continue.