Expand description
§Example
Shows how to use the ntp library to fetch the current time according to the requested ntp server.
extern crate chrono;
extern crate broker_ntp;
use chrono::TimeZone;
fn main() {
let address = "0.pool.ntp.org:123";
let response = broker_ntp::request(address).unwrap();
let unix_time = broker_ntp::unix_time::Instant::from(response.transmit_timestamp);
let local_time = chrono::Local.timestamp(unix_time.secs(), unix_time.subsec_nanos() as _);
println!("{}", local_time);
}Modules§
Functions§
- request
- Send a blocking request to an ntp server with a hardcoded 5 second timeout.