| Crates.io | worldtimeapi |
| lib.rs | worldtimeapi |
| version | 0.5.3 |
| created_at | 2022-03-29 15:24:46.730134+00 |
| updated_at | 2025-06-03 21:39:38.036755+00 |
| description | A simple API for getting the current time in different timezones. |
| homepage | |
| repository | https://github.com/martial-plains/worldtimeapi-rs |
| max_upload_size | |
| id | 558573 |
| size | 71,573 |
This is a simple wrapper for the World Time API. This crate is based on the WorldTimeAPI wrapper by Dulatr.
To use this crate, add worldtimeapi to your Cargo.toml:
[dependencies]
worldtimeapi = "0.5.3"
Then create a client for an endpoint (currently they only offer "ip" and "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(())
}
To get a list of regions and locations, use the regions method:
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(())
}