| Crates.io | sntp_request |
| lib.rs | sntp_request |
| version | 2.0.1 |
| created_at | 2020-01-02 21:49:00.418766+00 |
| updated_at | 2022-12-21 05:12:18.745921+00 |
| description | Tiny Rust library to request timestamp from NTP servers trough SNTP protocol. |
| homepage | https://github.com/risoflora/sntp_request |
| repository | https://github.com/risoflora/sntp_request |
| max_upload_size | |
| id | 194620 |
| size | 32,548 |
sntp_requestsntp_request Tiny Rust library to request timestamps from NTP servers through SNTP protocol.
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);
}
Pull Requests are welcome! =)
sntp_request is licensed under the Apache License 2.0 or MIT License.