rust 获取 windows 系统运行时间

180it 2024-10-09 PM 131℃ 0条
[dependencies]
winapi = { version = "0.3", features = ["sysinfoapi"] }


extern crate winapi;

use winapi::um::sysinfoapi::GetTickCount64;

fn get_windows_uptime() -> u64 {
    unsafe { GetTickCount64() }
}




fn main() {
    // 获取系统运行时间(以毫秒为单位)
    let uptime_ms = get_windows_uptime();

    // 将运行时间转换为秒
    let uptime_secs = uptime_ms / 1000;

    // 将运行时间转换为小时、分钟和秒
    let days = uptime_secs / 86400;
    let hours = (uptime_secs % 86400) / 3600;
    let minutes = (uptime_secs % 3600) / 60;
    let seconds = uptime_secs % 60;

    println!("System uptime: {} days, {} hours, {} minutes, {} seconds", days, hours, minutes, seconds);
}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

rust 获取 windows 系统运行时间