Skip to content

Tiny Rust library to request timestamps from NTP servers through SNTP protocol.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

risoflora/sntp_request

Repository files navigation

sntp_request

CI/CD Crates.io Documentation License

sntp_request Tiny Rust library to request timestamps from NTP servers through SNTP protocol.

Example

The example below shows how to obtain precise timestamp from main NTP server:

use chrono::{Local, TimeZone};
use sntp_request::SntpRequest;

fn main() {
    let sntp = SntpRequest::new();
    let timestamp = Local.timestamp_opt(sntp.get_unix_time().unwrap(), 0);
    println!("{}", timestamp.unwrap());
}

Also, it is possible to get the raw timestamp, for example:

use sntp_request::SntpRequest;

fn main() {
    let sntp = SntpRequest::new();
    let timestamp = sntp.get_raw_time().unwrap();
    let nsec = (timestamp.frac as f64 / u32::max_value() as f64) * 1000.0;
    println!("seconds: {} frac: {}", timestamp.secs, timestamp.frac);
    println!("milliseconds: {}", nsec);
}

Contributions

Pull Requests are welcome! =)

License

sntp_request is licensed under the Apache License 2.0 or MIT License.

About

Tiny Rust library to request timestamps from NTP servers through SNTP protocol.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Languages