Skip to content

Instantly share code, notes, and snippets.

@vibbow
Created January 23, 2014 00:01
Show Gist options
  • Save vibbow/8570137 to your computer and use it in GitHub Desktop.
Save vibbow/8570137 to your computer and use it in GitHub Desktop.
优雅 (蛋疼) 的获取Linux开机时长
<?php
$uptime = file_get_contents('/proc/uptime'); // 1164820.24 4655047.46;
$upsecond = (int)explode(' ', $uptime)[0];
$datediff = date_diff(date_create(), date_create("{$upsecond} second ago"), true);
echo $datediff->y . "\r\n";
echo $datediff->m . "\r\n";
echo $datediff->d . "\r\n";
echo $datediff->h . "\r\n";
echo $datediff->i . "\r\n";
echo $datediff->s . "\r\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment