Konvertierung timestamp zu Zeit in PHP e.g 1 Tag, 2 Tage her...

Ich versuche zu konvertieren timestamp-format 2009-09-12 20:57:19 und verwandelt es in etwas wie 3 minutes ago mit PHP.

Fand ich ein nützliches script, um dies zu tun, aber ich denke, es ist die Suche nach einem anderen format verwendet werden, da die Zeit-variable. Das script-ich bin zu wollen, ändern Sie für die Arbeit mit diesem format ist:

function _ago($tm,$rcs = 0) {
    $cur_tm = time(); 
    $dif = $cur_tm-$tm;
    $pds = array('second','minute','hour','day','week','month','year','decade');
    $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);

    for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]);
        $no = floor($no);
        if($no <> 1)
            $pds[$v] .='s';
        $x = sprintf("%d %s ",$no,$pds[$v]);
        if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0))
            $x .= time_ago($_tm);
        return $x;
    }

Ich denke in den ersten paar Zeilen das script wird versuchen, etwas zu tun, die wie folgt aussieht (anderes Datum-format Mathematik):

$dif = 1252809479 - 2009-09-12 20:57:19;

Wie würde ich mich über meine Umwandlung timestamp in das (unix?) format?

InformationsquelleAutor willdanceforfun | 2009-09-13

Schreibe einen Kommentar