Date::getSocialTime
Get the elapsed time like social media ("10分前")
Description
public string Date::getSocialTime( string $date, [ string $timezone = '' ] )
Returns the time between $date and now in Japanese: N日前, N時間前, N分前 or N秒前 (the largest unit that is 1 or more). Returns an empty string when $date is now.
メモ
$timezone is the time zone $date is written in, for this call only. The time zone of the application ($settings['timezone']) is not changed. When it is omitted, the application's time zone is used.
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $date | string | Date and time | |
| $timezone | string | '' | Time zone of $date, e.g. Asia/Tokyo |
Example
Controller
use Fegg\Tool\Date;
$date = new Date();
echo $date->getSocialTime(date('Y-m-d H:i:s', time() - 600)); // -> "10分前"