Function tzdb::local_tz

source ·
pub fn local_tz() -> Option<TimeZoneRef<'static>>
Expand description

Find the time zone of the current system

This function uses iana_time_zone::get_timezone() in the background. You may want to cache the output to avoid repeated filesystem accesses by get_timezone().

Example

// Query the time zone of the local system:
let time_zone = tzdb::local_tz().unwrap();

Most likely you will want to fallback to a default time zone, if the system time zone could not be determined or was not found in the database:

// Query the time zone of the local system:
let time_zone = tzdb::local_tz().unwrap_or(tzdb::time_zone::GMT);