将秒转换为时间的功能


Function to convert seconds to time

我有这个函数,其中包含一个时间标记数组:

function TimeAgo($time, $ret = '') {
        $time = time() - strtotime($time); // to get the time since that moment
        $tokens = array (
        'year' => 31536000,
        'month' => 2592000,
        'week' => 604800,
        'day' => 86400,
        'hour' => 3600,
        'minute' => 60,
        'second' => 1
        );
}

我将检查$ret是否等于数组中的一个名称(年、月等),如果是,我想将$time转换为选定的

如何将$time转换为其中一个代币?

我想你想要这个:

return (isset($tokens[$ret])) ? $time/$tokens[$ret] : $time;