Zeigen Sie in PHP Codeigniter "time ago" anstelle von datetime an
Ich möchte ein Zeitformat wie Twitter und FB anzeigen (Gepostet vor 3 Stunden, Gepostet vor 2 Minuten und so weiter ...)
Ich habe diesen Code ohne Erfolg ausprobiert:
function format_interval($timestamp, $granularity = 2) {
$units = array('1 year|@count years' => 31536000, '1 week|@count weeks' => 604800, '1 day|@count days' => 86400, '1 hour|@count hours' => 3600, '1 min|@count min' => 60, '1 sec|@count sec' => 1);
$output = '';
foreach ($units as $key => $value) {
$key = explode('|', $key);
if ($timestamp >= $value) {
$floor = floor($timestamp / $value);
$output .= ($output ? ' ' : '') . ($floor == 1 ? $key[0] : str_replace('@count', $floor, $key[1]));
$timestamp %= $value;
$granularity--;
}
if ($granularity == 0) {
break;
}
}
Ich benutze diese Funktion mit einem Rückruf in eine andere Funktion wie: $ this-> format_interval (); und übergebe es meiner Ansicht
Mein aktuelles Formatdatum ist:2012-07-26 09: 31: pm und schon in meiner DB gespeichert
Jede Hilfe wird sehr geschätzt!