note 110750 modified in function.time by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Dec 2012 14:11:55 +0000 |
| Subject: | note 110750 modified in function.time by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192299@lists.php.net to get a copy of this message | ||
This function returns a string in the format of 'y, d, h, s' or 'year, day, hour,
second'(if $full is set to true) for a input value in seconds as $time.
An 's' is added to the units with values greater than 1 when returning a string in the
'year, day, hour, second' format.
<?php
function timetostring($time, $full=false){
$time=
($time>=31536000?floor($time/31536000).($full?"
year".(floor($time/31536000)>1?"s":""):"y").",
":"").
($time%31536000>=86400?floor($time%31536000/86400).($full?"
day".(floor($time%31536000/86400)>1?"s":""):"d").",
":"").
($time%31536000%86400>=3600?floor($time%31536000%86400/3600).($full?"
hour".(floor($time%31536000%86400/3600)>1?"s":""):"h").",
":"").
($time%31536000%86400%3600>=60?floor($time%31536000%86400%3600/60).($full?"
minute".(floor($time%31536000%86400%3600/60)>1?"s":""):"m").",
":"").
($time%31536000%86400%3600%60>0?($time%31536000%86400%3600%60).($full?"
second".(floor($time%31536000%86400%3600%60)>1?"s":""):"s").",
":"")
;
return substr($time,0,strlen($time)-2);
}
?>
--was--
This function returns a string in the format of 'y, d, h, s' or 'year, day, hour,
second'(if $full is set to true) for a input value in seconds as $time.
An 's' is added to the units with values greater than 1 when returning a string in the
'year, day, hour, second' format.
function timetostring($time, $full=false){
$time=
($time>=31536000?floor($time/31536000).($full?"
year".(floor($time/31536000)>1?"s":""):"y").",
":"").
($time%31536000>=86400?floor($time%31536000/86400).($full?"
day".(floor($time%31536000/86400)>1?"s":""):"d").",
":"").
($time%31536000%86400>=3600?floor($time%31536000%86400/3600).($full?"
hour".(floor($time%31536000%86400/3600)>1?"s":""):"h").",
":"").
($time%31536000%86400%3600>=60?floor($time%31536000%86400%3600/60).($full?"
minute".(floor($time%31536000%86400%3600/60)>1?"s":""):"m").",
":"").
($time%31536000%86400%3600%60>0?($time%31536000%86400%3600%60).($full?"
second".(floor($time%31536000%86400%3600%60)>1?"s":""):"s").",
":"")
;
return substr($time,0,strlen($time)-2);
}
http://php.net/manual/en/function.time.php