Skip to content

Instantly share code, notes, and snippets.

@ferdiunal
Created May 6, 2014 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferdiunal/ce49db383546e9a2bc6b to your computer and use it in GitHub Desktop.
Save ferdiunal/ce49db383546e9a2bc6b to your computer and use it in GitHub Desktop.
Strtotime Geçen zamanı hesaplama
// Geçen Zaman
function GecenZaman(gecenSure){
if(gecenSure){
var myDate = new Date();
var $zaman = (myDate.getTime() /1000) - gecenSure;
var $yil,$ay,$hafta,$gun,$saat,$dakika,$saniye,$sure;
$sure = "";
$yil = Math.floor($zaman / 31536000);
if(typeof $yil != 'undefined' && $yil > 0){
$sure += $yil + " yıl, ";
}
$zaman -= $yil * 31536000;
$ay = Math.floor($zaman / 2628000);
if($yil > 0 || $ay > 0){
if( typeof $ay != 'undefined' && $ay > 0){
$sure += $ay + " ay, ";
}
$zaman -= $ay * 2628000;
}
$hafta = Math.floor($zaman / 604800);
if($yil > 0 || $ay > 0 || $hafta > 0){
if( typeof $hafta != 'undefined' && $hafta > 0){
$sure += $hafta + " hafta, ";
}
$zaman -= $hafta * 604800;
}
$gun = Math.floor($zaman / 86400);
if($ay > 0 || $hafta > 0 || $gun > 0){
if( typeof $gun != 'undefined' && $gun > 0){
$sure += $gun + " gün, ";
}
$zaman -= $gun * 86400;
}
$saat = Math.floor($zaman / 3600);
if($hafta > 0 || $gun > 0 || $saat > 0){
if( typeof $saat != 'undefined' && $saat > 0){
$sure += $saat + " saat, ";
}
$zaman -= $saat * 3600;
}
$dakika = Math.floor($zaman / 60);
if($gun > 0 || $saat > 0 || $dakika > 0){
if( typeof $dakika != 'undefined' && $dakika > 0){
$sure += $dakika + " dakika, ";
}
$zaman -= $dakika * 60;
}
if($sure == ""){
$sure += Math.floor($zaman) + " saniye, ";
}
return $sure.substring(0,$sure.length - 2) + " önce ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment