Example:
~~~
echo 'Human Friendly: ' . Enum::timeElapsed("2011-08-30 03:11:39");
echo 'Raw Conversion: ' . Enum::timeElapsed("2011-08-30 03:11:39", false);
~~~
public static timeInterval ( integer $interval, string $append = null, boolean $human = true ) : string | ||
$interval | integer | time interval in seconds |
$append | string | the string to append for the converted elapsed time. Defaults to `' ago'`. |
$human | boolean | if true returns an approximate human friendly output. If set to `false`, will attempt an exact conversion of time intervals. |
return | string |
/** * Helper to convert expiry time left from now * * @param string $type the expiry time type * @param int $seconds the time left in seconds * * @return string */ public static function timeLeft($type, $seconds) { if ($seconds > 0) { return Yii::t('user', 'The {type} link will expire in {time} from now.', ['type' => $type, 'time' => Enum::timeInterval($seconds, '')]); } return ''; }