tzdb::now

Function in_named

Source
pub fn in_named(tz: impl AsRef<[u8]>) -> Result<DateTime, NowError>
Expand description

Get the current time in a given time zone, by name

§Errors

Possible errors include:

  • The current Unix time could not be determined.
  • The current Unix time could not be projected into the time zone. Most likely the system time is off, or you are a time traveler trying run this code a few billion years in the future or past.
  • The time zone is not a valid IANA time zone.

§Example

// What is the time in Berlin?
let now = tzdb::now::in_named("Europe/Berlin")?;

In most cases you will want to default to a specified time zone if the time zone was not found. Then use e.g.

let now = tzdb::now::in_named_or(tzdb::time_zone::GMT, "Some/City")?;

§See also: