#时区 #不同 #获取 #世界 #时间 #包装器 #客户端

worldtimeapi

一个简单的API,用于获取不同时区的当前时间

8个版本 (4个破坏性更新)

0.5.2 2024年8月5日
0.5.1 2024年5月24日
0.5.0 2023年10月18日
0.4.1 2022年12月14日
0.1.0 2022年3月29日

Web编程中排名第563

Download history 86/week @ 2024-04-22 152/week @ 2024-05-20 9/week @ 2024-05-27 5/week @ 2024-07-01 115/week @ 2024-08-05

每月下载量115

MIT许可证

17KB
184

世界时间包装器

Rust

这是一个对World Time API的简单包装。这个crate基于Dulatr的WorldTimeAPI包装器

用法

要使用此crate,将worldtimeapi添加到您的Cargo.toml

[dependencies]
worldtimeapi = "0.5.1"

然后为端点创建一个客户端(目前它们只提供"ip"和"timezone")

use std::collections::HashMap;

use worldtimeapi::service::{Client, Endpoint};

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
   let client = Client::new(Endpoint::Timezone).await?;

   let mut payload = HashMap::new();
   payload.insert("area", "America");
   payload.insert("location", "New_York");

   let result = client.get(payload).await?;
   println!("{}", result.datetime());
   Ok(())
}

要获取地区和位置列表,请使用regions方法

use worldtimeapi::service::{Client, Endpoint};

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
   let client = Client::new(Endpoint::Timezone).await?;
   let regions = client.regions();
   println!("{:?}", regions);
   Ok(())
}

依赖关系

~5–17MB
~242K SLoC