blocking_with_chrono/
blocking_with_chrono.rs1#[cfg(feature = "chrono")]
2use chrono::{DateTime, Duration, Local, Utc};
3
4#[cfg(feature = "chrono")]
5fn chrono_example() {
6 let client = rsntp::SntpClient::new();
7 let time_info = client.synchronize("pool.ntp.org").unwrap();
8
9 let clock_offset: Duration = time_info.clock_offset().try_into().unwrap();
10 println!("Clock offset: {} ms", clock_offset);
11
12 let round_trip_delay: Duration = time_info.clock_offset().try_into().unwrap();
13 println!("Round trip delay: {} ms", round_trip_delay);
14
15 let datetime_utc: DateTime<Utc> = time_info.datetime().try_into().unwrap();
16 let local_time: DateTime<Local> = DateTime::from(datetime_utc);
17 println!("Local time: {}", local_time);
18
19 println!(
20 "Reference identifier: {}",
21 time_info.reference_identifier().to_string()
22 );
23 println!("Stratum: {}", time_info.stratum());
24}
25
26fn main() {
27 #[cfg(feature = "chrono")]
28 chrono_example();
29}