Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




human_time_diff [ WordPress Function ]

human_time_diff ( $from, $to = '' )
Parameters:
  • (int) $from Unix timestamp from which the difference begins.
  • (int) $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
Returns:
  • (string) Human readable time difference.
Defined at:



Determines the difference between two timestamps.

The difference is returned in a human readable format such as "1 hour", "5 mins", "2 days".

Source


<?php
function human_time_diff$from$to '' ) {
    if ( empty(
$to) )
        
$to time();
    
$diff = (int) abs($to $from);
    if (
$diff <= 3600) {
        
$mins round($diff 60);
        if (
$mins <= 1) {
            
$mins 1;
        }
        
/* translators: min=minute */
        
$since sprintf(_n('%s min''%s mins'$mins), $mins);
    } else if ((
$diff <= 86400) && ($diff 3600)) {
        
$hours round($diff 3600);
        if (
$hours <= 1) {
            
$hours 1;
        }
        
$since sprintf(_n('%s hour''%s hours'$hours), $hours);
    } elseif (
$diff >= 86400) {
        
$days round($diff 86400);
        if (
$days <= 1) {
            
$days 1;
        }
        
$since sprintf(_n('%s day''%s days'$days), $days);
    }
    return 
$since;
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics