欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-04-09 19:17:12
...

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

  1. $exec = shell_exec('uptime');
  2. $uptime = explode(' up ', $exec);
  3. $uptime = explode(',', $uptime[1]);
  4. if (strpos($uptime[0], 'day')) {
  5. $time = explode(':', $uptime[1]);
  6. echo('Current system uptime is ' . $uptime[0]. ', ' . $time[0] . ' hours, ' . $time[1] . ' minutes');
  7. } elseif (strpos($uptime[0], ':')) {
  8. $time = explode(':', $uptime[0]);
  9. echo('Current system uptime is ' . $time[0] . ' hours, ' . $time[1] . ' minutes');
  10. } else {
  11. $time = explode(' ', $uptime[0]);
  12. echo('Current system uptime is ' . $time[0] . ' minutes');
  13. }
  14. ?>
复制代码

转换成, php, linux