PHP 取 Windows 启动时间及计算已启动秒数

// 代码使用 nesbot/carbon 包

// get last bootup time
exec('WMIC OS GET LastBootUpTime', $output);

$bootUpTime = current(explode('+', $output[1]));
$bootUpTime = Carbon::createFromFormat('YmdHis.u', $bootUpTime)->timestamp;

$bootedSeconds = Carbon::now()->timestamp - $bootUpTime;

echo "系统已运行:{$bootedSeconds} 秒";

评论

暂无评论