[time.clock.system] (original) (raw)

30.7.2.1 Overview [time.clock.system.overview]

namespace std::chrono { class system_clock { public: using rep = see below;using period = ratio<_unspecified_, _unspecified_>;using duration = chrono::duration<rep, period>;using time_point = chrono::time_point<system_clock>;static constexpr bool is_steady = unspecified;static time_point now() noexcept;static time_t to_time_t (const time_point& t) noexcept;static time_point from_time_t(time_t t) noexcept;};}

Objects of type system_clock represent wall clock time from the system-wide realtime clock.

Objects of type sys_time<Duration> measure time since 1970-01-01 00:00:00 UTC excluding leap seconds.

This measure is commonly referred to as Unix time.

This measure facilitates an efficient mapping betweensys_time and calendar types ([time.cal]).

[Example 1:

sys_seconds{sys_days{1970y/January/1}}.time_since_epoch() is 0s.

sys_seconds{sys_days{2000y/January/1}}.time_since_epoch() is 946'684'800s, which is 10'957 * 86'400s.

— _end example_]

30.7.2.2 Members [time.clock.system.members]

using system_clock::rep = _unspecified_;

Constraints: system_clock​::​duration​::​min() < system_clock​::​duration​::​zero() is true.

[Note 1:

This implies that rep is a signed type.

— _end note_]

static time_t to_time_t(const time_point& t) noexcept;

Returns: A time_t object that represents the same point in time as twhen both values are restricted to the coarser of the precisions of time_t andtime_point.

It is implementation-defined whether values are rounded or truncated to the required precision.

static time_point from_time_t(time_t t) noexcept;

Returns: A time_point object that represents the same point in time as twhen both values are restricted to the coarser of the precisions of time_t andtime_point.

It is implementation-defined whether values are rounded or truncated to the required precision.

30.7.2.3 Non-member functions [time.clock.system.nonmembers]

template<class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const sys_time<Duration>& tp);

Constraints: treat_as_floating_point_v<typename Duration​::​rep> is false, andDuration{1} < days{1} is true.

Effects: Equivalent to:return os << format(os.getloc(), _STATICALLY-WIDEN_<charT>("{:L%F %T}"), tp);

[Example 1: cout << sys_seconds{0s} << '\n'; cout << sys_seconds{946'684'800s} << '\n'; cout << sys_seconds{946'688'523s} << '\n'; — _end example_]

template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const sys_days& dp);

Effects: os << year_month_day{dp}.

template<class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, sys_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr);

Effects: Attempts to parse the input stream isinto the sys_time tp using the format flags given in the NTCTS fmtas specified in [time.parse].

If the parse fails to decode a valid date,is.setstate(ios_base​::​failbit) is called andtp is not modified.

If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null.

If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null.

Additionally, the parsed offset will be subtracted from the successfully parsed timestamp prior to assigning that difference to tp.