To print an entry’s time (“2 days ago”):
<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>
For comments:
<?php echo human_time_diff( get_comment_time('U'), current_time('timestamp') ) . ' ago'; ?>
Or if you want a shorter code to implement, you can add a php function in functions.php file of your theme folder:
function time_ago( $type = 'post' ) { $d = 'comment' == $type ? 'get_comment_time' : 'get_post_time'; return human_time_diff($d('U'), current_time('timestamp')) . " " . __('ago'); }
and echo it as:
<?php echo time_ago(); ?>