1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- function ght($ts,$fa=null,$sd=2) {
- /*
- $ts is seconds (can be float)
- if not null, $fa has to be an array defining the output suffixes, see below
- its default ;-)
- $sd is how many decimals to put after a dot after seconds (can be 0)
- */
- if ($fa==null)
- $fa=[' year, ',' years, ',' week, ',' weeks, ',' day, ',' days, ',' hour, ',' hours, ',' minute, ',' minutes, ',' second',' seconds'];
- $out='';
- $i=0;
- // years
- $x=floor($ts/31536000);
- if ($x>0)
- ($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
- $ts=$ts-$x*31536000;
- $i+=2;
- // weeks
- $x=floor($ts/604800);
- if ($x>0)
- ($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
- $ts=$ts-$x*604800;
- $i+=2;
- // days
- $x=floor($ts/86400);
- if ($x>0)
- ($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
- $ts=$ts-$x*86400;
- $i+=2;
- // hours
- $x=floor($ts/3600);
- if ($x>0)
- ($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
- $ts=$ts-$x*3600;
- $i+=2;
- // minutes
- $x=floor($ts/60);
- if ($x>0)
- ($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
- $ts=$ts-$x*60;
- $i+=2;
- // seconds
- $x=round($ts,$sd);
- ($x==1) ? $out.=$x.$fa[$i] : $out.=$x.$fa[$i+1];
- return $out;
- }
- ?>
|