Formats the given absl::Time in the absl::TimeZone according to the provided format string. Uses strftime()‐like formatting options, with the following extensions:

Synopsis

Declared in <absl/time/time.h>

std::string
FormatTime(
    std::string_view format,
    Time t,
    TimeZone tz);

Description

  • %Ez ‐ RFC3339‐compatible numeric UTC offset (+hh:mm or ‐hh:mm)

  • %E*z ‐ Full‐resolution numeric UTC offset (+hh:mm:ss or ‐hh:mm:ss)

  • %E#S ‐ Seconds with # digits of fractional precision

  • %E_S ‐ Seconds with full fractional precision (a literal '_')

  • %E#f ‐ Fractional seconds with # digits of precision

  • %E_f ‐ Fractional seconds with full precision (a literal '_')

  • %E4Y ‐ Four‐character years (‐999 ... ‐001, 0000, 0001 ... 9999)

  • %ET ‐ The RFC3339 "date‐time" separator "T"

Note that %E0S behaves like %S, and %E0f produces no characters. In contrast %E*f always produces at least one digit, which may be '0'.

Note that %Y produces as many characters as it takes to fully render the year. A year outside of [‐999:9999]when formatted with %E4Y will produce more than four characters, just like %Y.

We recommend that format strings include the UTC offset (%z, %Ez, or %E*z) so that the result uniquely identifies a time instant.

Example:

absl::CivilSecond cs(2013, 1, 2, 3, 4, 5); absl::Time t = absl::FromCivil(cs, lax); std::string f = absl::FormatTime("%H:%M:%S", t, lax); // "03:04:05" f = absl::FormatTime("%H:%M:%E3S", t, lax); // "03:04:05.000"

Note: If the given absl::Time is absl::InfiniteFuture(), the returned string will be exactly "infinite‐future". If the given absl::Time is absl::InfinitePast(), the returned string will be exactly "infinite‐past". In both cases the given format string and absl::TimeZone are ignored.

Return Value

The formatted time string.

Parameters

Name

Description

format

The strftime()‐like format string.

t

The time to format.

tz

The time zone to format in.

Created with MrDocs