Timp minute /secunde in urma
Scris: Vin Iul 08, 2011
Buna...cum pot sa fac data asa: Postat cu 2 secunde in urma/ Postat cu 10 ore in urma...Asa cum e si pe Forum cand postezi un post/reply...? Ms mult!
Cursuri online, tutoriale, jocuri si anime - gratuite
https://marplo.net/forum/
Cod: Selectaţi tot
<?php
// www.phpsnippets.info
function timeAgo($timestamp, $granularity=3, $format='Y-m-d H:i:s'){
$difference = time() - $timestamp;
if($difference < 0) return '0 secunde in urma';
elseif($difference < 31570560){
$periods = array('luni'=>2592000, 'saptamani'=>604800, 'zi'=>86400, 'ore'=>3600, 'minute'=>60, 'secunde'=>1);
$output = '';
foreach($periods as $key => $value){
if($difference >= $value){
$time = round($difference / $value);
$difference %= $value;
$output .= ($output ? ' ' : '').$time.' ';
$output .= (($time > 1 && $key == 'zi') ? $key.'le' : $key);
$granularity--;
}
if($granularity == 0) break;
}
return 'Acum '. ($output ? $output : '0 secunde');
}
else return date($format, $timestamp);
}
echo timeAgo(1300191698);
?>
Cod: Selectaţi tot
<?php
// ... cod functie de mai sus si preluare timp de unde il ai salvat
$timp = timp_unix;
$dela = timeAgo($timp);
echo $dela;
?>