vitao.web Posted December 2, 2010 Report Share Posted December 2, 2010 (edited) Labdien! Ja kādam vajag Facebook,twitter stila laiku: - pievienots: pirms 1 stundas. Tad lūk kods: function getAge($iTimestamp) { $iCurrentTimestamp = mktime(); $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 te kā izmantot: $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']; $time = strtotime($time); $age = getAge($time); //talak jau to ko tev vajag. } Ceru, ka kādam noderēs! Paldies visiem, kas palīdzēja tikt galā! Edited December 7, 2010 by vitao.web Link to comment Share on other sites More sharing options...
rATRIJS Posted December 2, 2010 Report Share Posted December 2, 2010 o_O tu uzrakstiiji funkciju un nezini kaa to izmantot? $age = getAge(time() - 3600); Link to comment Share on other sites More sharing options...
vitao.web Posted December 2, 2010 Author Report Share Posted December 2, 2010 (edited) 1) Neteicu ka rakstīju pats visu 2) Es tik mācos, un tādēļ domāju paspēlēties, bet nesapratu kā īsti to timestamp norādīt :( Shame one me Man rāda erroru: Strict Standards: mktime() [function.mktime]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for '2.0/no DST' instead in C:\AppServ\www\darbs\function.php on line 12 Un otrs errors ir tas ka mktime() vieta vajadzetu likt time() Kā no tā varētu izvairīties? Edited December 2, 2010 by vitao.web Link to comment Share on other sites More sharing options...
xPtv45z Posted December 2, 2010 Report Share Posted December 2, 2010 Erroru pamēģināji izlasīt? :D ...Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function.... Link to comment Share on other sites More sharing options...
vitao.web Posted December 2, 2010 Author Report Share Posted December 2, 2010 Erroru pamēģināji izlasīt? :D Izlasiju, bet kur tad es to funkciju var izmantot? :( Jo ja es mainu to mktime() tad visas funkcijas jega zud :( Link to comment Share on other sites More sharing options...
nikidijs Posted December 2, 2010 Report Share Posted December 2, 2010 izlabo php.ini failā - timezones settingu (uz savu laika zonu) un būs ok :) Link to comment Share on other sites More sharing options...
vitao.web Posted December 2, 2010 Author Report Share Posted December 2, 2010 izlabo php.ini failā - timezones settingu (uz savu laika zonu) un būs ok :) Liels paldies :) Link to comment Share on other sites More sharing options...
indoom Posted December 2, 2010 Report Share Posted December 2, 2010 errors gan tas nav, bet tur jau rakstīts, ka jāizmanto date_default_timezone_set(), lai tas warnings nerādītos. Piem., date_default_timezone_set('Europe/Riga'); Link to comment Share on other sites More sharing options...
vitao.web Posted December 2, 2010 Author Report Share Posted December 2, 2010 errors gan tas nav, bet tur jau rakstīts, ka jāizmanto date_default_timezone_set(), lai tas warnings nerādītos. Piem., date_default_timezone_set('Europe/Riga'); tavs variants palīdzēja, bet to erroru/bridinājumu ka mktime() vieta vajag time() nevaru dabut nost :( Link to comment Share on other sites More sharing options...
Val Posted December 2, 2010 Report Share Posted December 2, 2010 Kāpēc neizmanto time()? Link to comment Share on other sites More sharing options...
Mr.Key Posted December 2, 2010 Report Share Posted December 2, 2010 2) Es tik mācos, un tādēļ domāju paspēlēties, bet nesapratu kā īsti to timestamp norādīt :( Shame one me Tu nepareizi mācies. Kad es mācījos, pēc pusgada jau mācīju citus un tekoši lasīju angliski, a tu joprojām uzdod stulbus jautājumus. Iesaku radikāli kaut ko mainīt un mācīties centīgāk. Vai mest mieru. Link to comment Share on other sites More sharing options...
vitao.web Posted December 2, 2010 Author Report Share Posted December 2, 2010 Tu nepareizi mācies. Kad es mācījos, pēc pusgada jau mācīju citus un tekoši lasīju angliski, a tu joprojām uzdod stulbus jautājumus. Iesaku radikāli kaut ko mainīt un mācīties centīgāk. Vai mest mieru. Paldies par padomu, kas attiecās uz lietu - viss atrisināts! Paldies par palīdzību. Link to comment Share on other sites More sharing options...
vitao.web Posted December 7, 2010 Author Report Share Posted December 7, 2010 Labdien! Piedodiet, ka atkal uzplīšos ar savu jautājumu! Lieta tāda, ka nevaru izdomāt kā lai šito funkciju izmanto laikam, kas nāk no DB ieraksta? query: $izs = dbFetch("SELECT id, title, cat,message,DATE_FORMAT(date, '%b %d %Y %h:%i %p') AS newdate FROM blog ORDER BY id DESC LIMIT 8;"); Tad, kā es to funkciju varu izmantot šim variantam. Tas ko rartijs rādija strādā ideāli, bet tas viss notiek manu;ali, bet vajag dinamiski. Paldies! Link to comment Share on other sites More sharing options...
rATRIJS Posted December 7, 2010 Report Share Posted December 7, 2010 $r = mysql_fetch_assoc($izs); $time = $r['newdate']; $time = strtotime($time); $age = getAge($time); Ja kaut kas nav kaa vajag lasi sho: http://php.net/manual/en/function.strtotime.php Alternatiivi vari izmantot explode vai preg_match lai paarveerstu datumu par unix timestamp. Link to comment Share on other sites More sharing options...
Mr.Key Posted December 7, 2010 Report Share Posted December 7, 2010 (edited) Nu man liekas, ka unix_timestamp no mysql DATE var dabūt ar UNIX_TIMESTAMP(date) $izs = dbFetch("SELECT id, title, cat,message,DATE_FORMAT(date, '%b %d %Y %h:%i %p') AS newdate, UNIX_TIMESTAMP(date) AS anotherdate FROM blog ORDER BY id DESC LIMIT 8;"); anotherdate būs timestamps, kuru varēs izmantot ar php Edited December 7, 2010 by Mr.Key Link to comment Share on other sites More sharing options...
Recommended Posts