龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

时间转换 php将linux运行时间转换成更好看的格式

时间:2014-05-30 15:21来源:网络整理 作者:网络 点击:
分享到:
php将linux运行时间转换成更好看的格式 [代码片段(17行)]
<?php
    $exec = shell_exec('uptime');
    $uptime = explode(' up ', $exec);
    $uptime = explode(',', $uptime[1]);
    if (strpos($uptime[0], 'day')) {
        $time = explode(':', $uptime[1]);
        echo('Current system uptime is ' . $uptime[0]. ', ' . $time[0] . ' hours, ' . $time[1] . ' minutes');
    } elseif (strpos($uptime[0], ':')) {
        $time = explode(':', $uptime[0]);
        echo('Current system uptime is ' .  $time[0] . ' hours, ' . $time[1] . ' minutes');
    } else {
        $time = explode(' ', $uptime[0]);
        echo('Current system uptime is ' .  $time[0] . ' minutes');
    }

?>

精彩图集

赞助商链接