当前位置 : 主页 > 网络编程 > PHP >

将linux运行时间格式成易读格式的php代码

来源:互联网 收集:自由互联 发布时间:2021-07-03
?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] . ' h
<?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');
    }

?>
网友评论