Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display time difference in human readable form in Yii2 (for example 2 days ago)?

Tags:

yii2

Does anyone who know how to count date time for notification ..for example "a few ago" or just now like this:

I hope anyone can help me to solve this problem:

<li>
    <a href="javascript:;">
        <span class="time">3 mins</span>
        <span class="details">
        <span class="label label-sm label-icon label-danger">
            <i class="fa fa-bolt"></i>
        </span> Server #12 overloaded. </span>
    </a>
</li>
like image 809
zack Avatar asked Dec 22 '15 19:12

zack


1 Answers

Use the build-in formatter with the relative time format:

<?php echo Yii::$app->formatter->format($timeOfEvent, 'relativeTime') ?>
like image 167
tarleb Avatar answered Oct 15 '22 23:10

tarleb