1 个不稳定版本

使用旧的Rust 2015

0.2.0 2018年2月20日

#833Unix API

Download history • Rust 包仓库 108/week @ 2024-04-08 • Rust 包仓库 156/week @ 2024-04-15 • Rust 包仓库 229/week @ 2024-04-22 • Rust 包仓库 134/week @ 2024-04-29 • Rust 包仓库 293/week @ 2024-05-06 • Rust 包仓库 294/week @ 2024-05-13 • Rust 包仓库 319/week @ 2024-05-20 • Rust 包仓库 109/week @ 2024-05-27 • Rust 包仓库 230/week @ 2024-06-03 • Rust 包仓库 189/week @ 2024-06-10 • Rust 包仓库 200/week @ 2024-06-17 • Rust 包仓库 210/week @ 2024-06-24 • Rust 包仓库 142/week @ 2024-07-01 • Rust 包仓库 126/week @ 2024-07-08 • Rust 包仓库 102/week @ 2024-07-15 • Rust 包仓库 153/week @ 2024-07-22 • Rust 包仓库

533 每月下载量

MIT 许可证

8KB
115

hwclock-rs

hwclock 模块通过内核结构和ioctl提供对硬件时钟当前时间的薄包装,并将其从有效 chrono 数据结构转换过来。

示例

extern crate chrono;
extern crate hwclock;

fn main() {
   use hwclock::HwClockDev;

   let rtc = HwClockDev::open("/dev/rtc0").expect("could not open rtc clock");

   println!("{:?}", rtc);

   let time = rtc.get_time().expect("could not read rtc clock");
   println!("{:?}", time);

   println!("Setting clock ahead 30 seconds");
   let mut ct: chrono::NaiveDateTime = time.into();
   ct += chrono::Duration::seconds(30);

   // convert back to RtcTime and set it
   let ntime = ct.into();
   rtc.set_time(&ntime).expect("could not set rtc clock");

   println!("Rereading...");
   let time2 = rtc.get_time().expect("could not read rtc clock");

   println!("{:?}", time2);
}

lib.rs:

Linux硬件时钟处理

hwclock 模块通过内核结构和ioctl提供对硬件时钟当前时间的薄包装,并将其从有效 chrono 数据结构转换过来。

extern crate chrono;
extern crate hwclock;

fn main() {
    use hwclock::HwClockDev;

    let rtc = HwClockDev::open("/dev/rtc0").expect("could not open rtc clock");

    println!("{:?}", rtc);

    let time = rtc.get_time().expect("could not read rtc clock");
    println!("{:?}", time);

    println!("Setting clock ahead 30 seconds");
    let mut ct: chrono::NaiveDateTime = time.into();
    ct += chrono::Duration::seconds(30);

    // convert back to RtcTime and set it
    let ntime = ct.into();
    rtc.set_time(&ntime).expect("could not set rtc clock");

    println!("Rereading...");
    let time2 = rtc.get_time().expect("could not read rtc clock");

    println!("{:?}", time2);
}

依赖关系

~3MB
~59K SLoC