| Crates.io | ntp-client |
| lib.rs | ntp-client |
| version | 0.1.0 |
| created_at | 2025-04-22 08:22:55.128572+00 |
| updated_at | 2025-04-22 08:22:55.128572+00 |
| description | The ntp-client is a Rust library designed for interacting with NTP (Network Time Protocol) servers. It enables developers to easily obtain accurate time information from NTP servers. This can be applied in scenarios such as calibrating system time and performing time synchronization. The library offers a simple and user - friendly API, and also features good performance and stability. |
| homepage | https://gitee.com/eternalnight996 |
| repository | |
| max_upload_size | |
| id | 1643714 |
| size | 54,438 |
ntp-client is a Rust library designed for interacting with NTP (Network Time Protocol) servers. It enables developers to conveniently obtain accurate time information from NTP servers, which can be used in scenarios such as calibrating system time and performing time synchronization. The library provides a simple and easy-to-use API, along with good performance and stability.
δΈζ | English
[dependencies]
ntp-client = { version="0.1", features=["sync-system"] }
fn main() -> e_utils::AnyResult<()> {
let target = "0.pool.ntp.org:123";
let res = ntp_client::Client::new()
.target(target)?
.format(Some("%Y/%m/%d %H:%M:%S"))
.request()?;
let res_str = res.get_datetime_str().ok_or("error")?;
println!("UTC str -> {res_str}");
let datetime = res.get_datetime_utc().ok_or("get datetime utc")?;
ntp_client::sync_systemtime(datetime)?;
Ok(())
}
use e_utils::chrono::FixedOffset;
fn main() -> e_utils::AnyResult<()> {
let target = "0.pool.ntp.org:123";
let res = ntp_client::Client::new()
.target(target)?
.format(Some("%Y/%m/%d %H:%M:%S"))
.offset(FixedOffset::east_opt(8 * 3600))
.request()?;
let res_str = res.get_datetime_str().ok_or("error")?;
println!("ShangHai str -> {res_str}");
Ok(())
}
We welcome contributions in any form!
Before submitting a PR, please ensure that:
This project is dual-licensed under MIT and LICENSE.