vitao.web Posted December 7, 2010 Report Share Posted December 7, 2010 (edited) Labdien! Paldies foruma biedriem, kas ļāva dabūt gatavu šo te "scriptu". Gan jau ka daudziem jau tāds ir , bet ir arī tādi, kā es piemēram, kas vēl daudz ko nezina, tādēļ šis būtu noderīgs. Pati funkcija: function getAge($iTimestamp) { $iCurrentTimestamp = time(); $iDifference = $iCurrentTimestamp - $iTimestamp; $iOriginalDifference = $iDifference; $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade"); $lengths = array("60","60","24","7","4.35","12","10"); for($j = 0; $iDifference >= $lengths[$j]; $j++) $iDifference /= $lengths[$j]; if ($j == 6) { $sReturn = date('M Y',time() - $iOriginalDifference); } else { $iDifference = round($iDifference); if($iDifference != 1) $periods[$j] .= "s"; $sReturn = $iDifference . " " . $periods[$j] . " " . $ending . " ago"; } if (trim($sReturn) == '1 day ago') $sReturn = "yesterday"; return $sReturn; } Un pielietojums, kādu nu katrs grib, te piemēri daži: $age = getAge(time() - 3600); vai ja izmanto DB: $izs = dbFetch("SELECT id, title, cat,message,DATE_FORMAT(date, '%b %d %Y %h:%i %p') AS newdate, UNIX_TIMESTAMP(date) AS laiks FROM blog ORDER BY id DESC LIMIT 8;"); while($rez = mysql_fetch_assoc($izs)){ $time = $rez['laiks']; $age = getAge($time); //talak jau to ko tev vajag. } Ceru, ka kādam noderēs! Un vēlreiz paldies palīgiem ;) Edited December 8, 2010 by vitao.web Quote Link to comment Share on other sites More sharing options...
indoom Posted December 8, 2010 Report Share Posted December 8, 2010 Bet kas ir UNIX_TIMESTAMP(), tomēr neesi sapratis. $time = strtotime($time); ir lieks Quote Link to comment Share on other sites More sharing options...
vitao.web Posted December 8, 2010 Author Report Share Posted December 8, 2010 Bet kas ir UNIX_TIMESTAMP(), tomēr neesi sapratis. $time = strtotime($time); ir lieks Vainīgs! :) Nepareizo kodu ieliku, veco , nevis jauno. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.