SphereCommunity
spherestatusbase - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: spherestatusbase (/Thread-spherestatusbase)



spherestatusbase - Leonidas - 09-06-2013 09:49 PM

I'm trying to show an uptime on my server status, I read on the wiki and saw I could use %TIME%, but it said it shows the uptime in tenths of a second. How would i do this so it would show the uptime in minutes, hours, or even days?

Thanks for any help!


RE: spherestatusbase - RanXerox - 09-07-2013 12:56 AM

Well the first thing you need to know is how to tell time: http://www.wikihow.com/Teach-Kids-to-Tell-Time


RE: spherestatusbase - Leonidas - 09-07-2013 07:02 AM

Although it was a very informative website, it did not help me figure my situation out


RE: spherestatusbase - RanXerox - 09-07-2013 07:21 AM

Then you need to know how to do math in a web page: http://www.scriptingmaster.com/javascript/performing-basic-math.asp


RE: spherestatusbase - KyleH112 - 10-09-2013 02:59 PM

(09-06-2013 09:49 PM)Leonidas Wrote:  I'm trying to show an uptime on my server status, I read on the wiki and saw I could use %TIME%, but it said it shows the uptime in tenths of a second. How would i do this so it would show the uptime in minutes, hours, or even days?

Thanks for any help!

If your hosting your server from a Windows machine and running PHP you can use something like this... What this script does is pulls your computers/servers pagefile.sys file which stores your computers/system/servers information and it will extract the uptime in this format ( #Days, #Hours, ##Minutes, ##Seconds) and will also show the last time the system was rebooted.


Code:
<?php
$pagefile = 'c:\pagefile.sys';

function ifif ($value, $true, $false)
{
    if ($value == 0)
    {
        return $false;
    }  
    else
    {
        return $true;
    }  
}  

$upsince = filemtime($pagefile);
$gettime = (time() - filemtime($pagefile));
$days = floor($gettime / (24 * 3600));
$gettime = $gettime - ($days * (24 * 3600));
$hours = floor($gettime / (3600));
$gettime = $gettime - ($hours * (3600));
$minutes = floor($gettime / (60));
$gettime = $gettime - ($minutes * 60);
$seconds = $gettime;

$days   = ifif($days != 1, $days . ' days', $hours . ' day');
$hours   = ifif($hours != 1, $hours . ' hours', $hours . ' hour');
$minutes = ifif($minutes != 1, $minutes . ' minutes', $minutes . ' minute');
$seconds = ifif($seconds != 1, $seconds . ' seconds', $seconds . ' second');

echo '<font color="red">Uptime:</font> ' . $days . ' ' . $hours . ' ' . $minutes . ' ' . $seconds;
echo '<br /> <font color="red"> Rebooted:</font> ' . date('l. F jS, Y. h:i a', $upsince);
?>