note 57110 added to language.types.float
| From: | TRI0N at osu1 dot php dot net | Date: | Sat, 24 Sep 2005 02:01:29 +0000 |
| Subject: | note 57110 added to language.types.float | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95675@lists.php.net to get a copy of this message | ||
Here is a simple formula to break down a number and get rid of the decimal values. I built this to
take a number in seconds and convert it to a readable value for Server Uptimes.
<?php
$day = floor(($uptime / 86400)*1.0) ;
$calc1 = $day * 86400 ;
$calc2 = $uptime - $calc1 ;
$hour = floor(($calc2 / 3600)*1.0) ;
if ($hour < 10) {
$hour = "0".$hour ;
}
$calc3 = $hour * 3600 ;
$calc4 = $calc2 - $calc3 ;
$min = floor(($calc4 / 60)*1.0) ;
if ($min < 10) {
$min = "0".$min ;
}
$calc5 = $min * 60 ;
$sec = floor(($calc4 - $calc5)*1.0) ;
if ($min < 10) {
$sec = "0".$sec ;
}
$uptime2 = $day." Days, ".$hour.":".$min.":".$sec ;
?>
Place this where you want the results to be seen:
<?php echo $uptime2 ; ?>
For a Value of 1455587 seconds the results will show as followed:
16 Days, 20:19:47
Enjoy
----
Manual Page -- http://www.php.net/manual/en/language.types.float.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57110
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57110&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57110&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57110&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57110&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57110&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57110&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57110&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57110&report=yes
Search -- http://master.php.net/manage/user-notes.php