0

コメント欄に経過時間を入れようとしています。

以下のコードを使用してみましたが、45 年経過しました。

これが私のコードです

    $data = $row['created_on'];
    $time = strtotime('$data');
    <li>
        <span class="author">
            <?php echo $row['name']; ?>
        </span>
        <span class="time">
            <?php echo ''.humanTiming($time).' ago'; ?>
        </span><br/>
        <div class="c_content">
            <?php echo $row['comment']; ?>
        </div>
        <div class="clear"></div>
    </li>
<?php } ?>
</ul>
<?php
function humanTiming ($time){ 
    $time = time() - $time; // to get the time since that moment
    $tokens = array (
        31536000 => 'year',
        2592000 => 'month',
        604800 => 'week',
        86400 => 'day',
        3600 => 'hour',
        60 => 'minute',
        1 => 'second'
    );
    foreach ($tokens as $unit => $text) {
        if ($time < $unit) continue;
        $numberOfUnits = floor($time / $unit);
        return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
    }
}
4

2 に答える 2