note 103075 deleted from function.date by danbrown

From: Date: Thu, 24 Mar 2011 13:56:08 +0000
Subject: note 103075 deleted from function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178159@lists.php.net to get a copy of this message
Note Submitter: Dilovan Matini ---- This function is similar to the function date in php <?php function date2($format,$time){ $time=(int)$time; $y=1970; $m=1; $d=1; $h=0; $i=0; $s=0; $time+=10800; if($time>0){ $months=array(31,28,31,30,31,30,31,31,30,31,30,31); while($time>0){ $isBad=((($y%4==0)&&($y%100!=0))||($y%400==0)); $ydays=($isBad ? 366 : 365); $ysec=($ydays*86400); if($time>=$ysec){ $y++; $time-=$ysec; } else{ while($time>0){ $mdays=($m==2&&$isBad ? 29 : $months[$m-1]); $msec=($mdays*86400); if($time>=$msec){ $m++; $time-=$msec; } else{ while($time>0){ $dsec=86400; if($time>=$dsec){ $d++; $time-=$dsec; } else{ while($time>0){ $hsec=3600; if($time>=$hsec){ $h++; $time-=$hsec; } else{ while($time>0){ $isec=60; if($time>=$isec){ $i++; $time-=$isec; } else{ $s=$time; $time=0; } } } } } } } } } } } $p=sprintf("%04d-%02d-%02d-%02d-%02d-%02d",$y,$m,$d,$h,$i,$s); $e=explode("-",$p); $date=str_replace( array('Y','m','d','H','i','s'), array($e[0],$e[1],$e[2],$e[3],$e[4],$e[5]), $format ); return $date; } echo date2("Y/m/d - H:i:s",1300914383); ?> output: 2011/03/24 - 00:06:23

« previous php.notes (#178159) next »