sntp_request
sntp_request
Tiny Rust library to request timestamp from NTP servers trough SNTP protocol.
The example below shows how to obtain precise timestamp from main NTP server:
```rust extern crate chrono; extern crate sntp_request;
use chrono::{Local, TimeZone}; use sntp_request::SntpRequest;
fn main() { let sntp = SntpRequest::new(); let timestamp = Local.timestamp(sntp.getunixtime().unwrap(), 0); println!("{}", timestamp); } ```
Also, it is possible to get the raw timestamp, for example:
```rust extern crate sntp_request;
use sntp_request::SntpRequest;
fn main() { let sntp = SntpRequest::new(); let timestamp = sntp.getrawtime().unwrap(); let nsec = (timestamp.frac as f64 / u32::max_value() as f64) * 1000.0; println!("seconds: {} frac: {}", timestamp.secs, timestamp.frac); println!("milliseconds: {}", nsec); } ```
Add this to your Cargo.toml
:
ini
[dependencies]
sntp_request = "2.0.0"
and this to your crate root:
rust
extern crate sntp_request;
Pull Requests and Issues are welcome!
sntp_request
is licensed under either of the following, at your option: