Good 4 Denunciar post Postado Maio 3, 2010 Alguém aqui sabe alguma função que possa fazer isso: Criado a 1 minuto atrás Criado a 2 minutos atrás Criado a 35 minutos atrás Criado a 2 horas atrás Criado a 22 horas atrás Criado a 2 dias atrás Pq to criando um sistema de notícias, ae preciso de um sistema desse ae.. Eu queria um que seja quase igual a esse.. flw Compartilhar este post Link para o post Compartilhar em outros sites
André D. Molin 15 Denunciar post Postado Maio 5, 2010 Dê uma olhada nesta função: <?php /* Relative Time Function based on code from http://stackoverflow.com/questions/11/how-do-i-calculate-relative-time/501415#501415 For use in the "Parse Twitter Feeds" code below */ define("SECOND", 1); define("MINUTE", 60 * SECOND); define("HOUR", 60 * MINUTE); define("DAY", 24 * HOUR); define("MONTH", 30 * DAY); function relativeTime($time) { $delta = strtotime('+2 hours') - $time; if ($delta < 2 * MINUTE) { return "1 min ago"; } if ($delta < 45 * MINUTE) { return floor($delta / MINUTE) . " min ago"; } if ($delta < 90 * MINUTE) { return "1 hour ago"; } if ($delta < 24 * HOUR) { return floor($delta / HOUR) . " hours ago"; } if ($delta < 48 * HOUR) { return "yesterday"; } if ($delta < 30 * DAY) { return floor($delta / DAY) . " days ago"; } if ($delta < 12 * MONTH) { $months = floor($delta / DAY / 30); return $months <= 1 ? "1 month ago" : $months . " months ago"; } else { $years = floor($delta / DAY / 365); return $years <= 1 ? "1 year ago" : $years . " years ago"; } } ?> Retirado daqui: http://spaceninja.com/2009/07/twitter-php-caching/ Compartilhar este post Link para o post Compartilhar em outros sites
Good 4 Denunciar post Postado Maio 8, 2010 vlw.. quem não estiver satisfeito com esta função, como eu.. vê ae: http://www.google.com.br/search?q=relative+time+php&hl=pt-BR&start=0&sa=N Compartilhar este post Link para o post Compartilhar em outros sites
Bruno Augusto 417 Denunciar post Postado Maio 8, 2010 Tudo bem que resolveu, mas ficam estas duas como reforço: function time_elapsed_string($ptime) { $etime = time() - $ptime; if ($etime < 1) { return '0 seconds'; } $a = array( 12 * 30 * 24 * 60 * 60 => 'year', 30 * 24 * 60 * 60 => 'month', 24 * 60 * 60 => 'day', 60 * 60 => 'hour', 60 => 'minute', 1 => 'second' ); foreach ($a as $secs => $str) { $d = $etime / $secs; if ($d >= 1) { $r = round($d); return $r . ' ' . $str . ($r > 1 ? 's' : ''); } } } Essa é mais direta. "Curta e grossa", no bom português. function nicetime($timestamp, $detailLevel = 1) { $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade"); $lengths = array("60", "60", "24", "7", "4.35", "12", "10"); $now = time(); // check validity of date if(empty($timestamp)) { return "Unknown time"; } // is it future date or past date if($now > $timestamp) { $difference = $now - $timestamp; $tense = "ago"; } else { $difference = $timestamp - $now; $tense = "from now"; } if ($difference == 0) { return "1 second ago"; } $remainders = array(); for($j = 0; $j < count($lengths); $j++) { $remainders[$j] = floor(fmod($difference, $lengths[$j])); $difference = floor($difference / $lengths[$j]); } $difference = round($difference); $remainders[] = $difference; $string = ""; for ($i = count($remainders) - 1; $i >= 0; $i--) { if ($remainders[$i]) { $string .= $remainders[$i] . " " . $periods[$i]; if($remainders[$i] != 1) { $string .= "s"; } $string .= " "; $detailLevel--; if ($detailLevel <= 0) { break; } } } return $string . $tense; } Essa é mais interessante pois mostra a data relativa completa de acordo com o valor do segundo parâmetro. Isto significa que se você informar, por exemplo: print nicetime( strtotime( '2 weeks ago -3 hours -25 minutes' ), 3 ); Obterá: 2 weeks 3 hours 25 minutes agoMas, tudo tem um porém, essa segunda função, pelo comentado no blog do autor essa funçãotem pequenas falhas de precisão nas semanas, principal mas não exclusivamente de Fevereiro e ainda não considera os "leap years", que deve ser os bissextos, já que eu não sei o que é "leap". Compartilhar este post Link para o post Compartilhar em outros sites