The absl::TimeZone is an opaque, small, value‐type class representing a geo‐political region within which particular rules are used for converting between absolute and civil times (see https://git.io/v59Ly). absl::TimeZone values are named using the TZ identifiers from the IANA Time Zone Database, such as "America/Los_Angeles" or "Australia/Sydney". absl::TimeZone values are created from factory functions such as absl::LoadTimeZone(). Note: strings like "PST" and "EDT" are not valid TZ identifiers. Prefer to pass by value rather than const reference.

Synopsis

Declared in <absl/time/time.h>

class TimeZone;

Description

For more on the fundamental concepts of time zones, absolute times, and civil times, see https://github.com/google/cctz#fundamental‐concepts

Examples:

absl::TimeZone utc = absl::UTCTimeZone(); absl::TimeZone pst = absl::FixedTimeZone(‐8 * 60 * 60); absl::TimeZone loc = absl::LocalTimeZone(); absl::TimeZone lax; if (!absl::LoadTimeZone("America/Los_Angeles", &lax)) { // handle error case }

See also:

  • https://github.com/google/cctz

  • https://www.iana.org/time‐zones

  • https://en.wikipedia.org/wiki/Zoneinfo

Types

Name

Description

CivilInfo

Information about the civil time corresponding to an absolute time. This struct is not intended to represent an instant in time. So, rather than passing a TimeZone::CivilInfo to a function, pass an absl::Time and an absl::TimeZone.

CivilTransition

A transition in a time zone: the civil times just before and after an offset change.

TimeInfo

Information about the absolute times corresponding to a civil time. (Subseconds must be handled separately.)

Member Functions

Name

Description

TimeZone [constructor]

Constructors

operator=

Assigns a copy of another time zone.

At

At overloads

NextTransition

Finds the next offset change in this time zone at or after a given time.

PrevTransition

Finds the previous offset change in this time zone before a given time.

name

Returns the TZ identifier name of this time zone.

operator /* implementation-defined */::cctz::time_zone

Converts this time zone to the underlying cctz time zone.

Friends

Name

Description

absl::operator<<

Writes the time zone's name to an output stream.

absl::operator!=

Returns whether two time zones are unequal.

absl::operator==

Returns whether two time zones are equal.

absl::AbslHashValue

Combines this time zone into a hash state.

Non-Member Functions

Name

Description

FixedTimeZone

Returns a TimeZone that is a fixed offset (seconds east) from UTC. Note: If the absolute value of the offset is greater than 24 hours you'll get UTC (i.e., no offset) instead.

LocalTimeZone

Convenience method returning the local time zone, or UTC if there is no configured local zone. Warning: Be wary of using LocalTimeZone(), and particularly so in a server process, as the zone configured for the local machine should be irrelevant. Prefer an explicit zone name.

UTCTimeZone

Convenience method returning the UTC time zone.

Created with MrDocs