#unix-timestamp #sntp #retrieve #requests #ntp #practice #port

simple-ntp

Library to retrieve Unix timestamps using SNTP requests

2 releases

0.1.1 Jun 3, 2023
0.1.0 Jun 3, 2023

#5 in #sntp

MIT license

11KB
216 lines

simple-ntp

Library to retrieve Unix timestamps using SNTP requests.

only for practice.

example

use cargo add simple-ntp.

cargo add simple-ntp

example code:

use simple_ntp::sntp;

fn main() {
    let timestamp = sntp::unix_timestamp("ntp.aliyun.com").unwrap();
    println!("{:?}", timestamp);

    // use specified port
    let timestamp = sntp::unix_timestamp("ntp.aliyun.com:123").unwrap();
    println!("{:?}", timestamp);

    let delta = sntp::clock_offset_nanos("ntp.aliyun.com").unwrap();
    println!("{:?}", delta as f64 / 1e9);
}

license

MIT license

No runtime deps