[time.clock.system] # 30 Time library [[time]](./#time) ## 30.7 Clocks [[time.clock]](time.clock#system) ### 30.7.2 Class system_clock [time.clock.system] #### [30.7.2.1](#overview) Overview [[time.clock.system.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; using time_point = chrono::time_point; static constexpr bool is_steady = *unspecified*; static time_point now() noexcept; // mapping to/from C type time_tstatic time_t to_time_t (const time_point& t) noexcept; static time_point from_time_t(time_t t) noexcept; };} [1](#overview-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2663) Objects of type system_clock represent wall clock time from the system-wide realtime clock[.](#overview-1.sentence-1) Objects of type sys_time measure time since 1970-01-01 00:00:00 UTC excluding leap seconds[.](#overview-1.sentence-2) This measure is commonly referred to as [*Unix time*](#def:Unix_time "30.7.2.1 Overview [time.clock.system.overview]")[.](#overview-1.sentence-3) This measure facilitates an efficient mapping betweensys_time and calendar types ([[time.cal]](time.cal "30.8 The civil calendar"))[.](#overview-1.sentence-4) [*Example [1](#overview-example-1)*: sys_seconds{sys_days{1970y/January/1}}.time_since_epoch() is 0s[.](#overview-1.sentence-5) sys_seconds{sys_days{2000y/January/1}}.time_since_epoch() is 946'684'800s, which is 10'957 * 86'400s[.](#overview-1.sentence-6) — *end example*] #### [30.7.2.2](#members) Members [[time.clock.system.members]](time.clock.system.members) [🔗](#lib:rep,system_clock) `using system_clock::rep = unspecified; ` [1](#members-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2686) *Constraints*: system_clock​::​duration​::​min() < system_clock​::​duration​::​zero() is true[.](#members-1.sentence-1) [*Note [1](#members-note-1)*: This implies that rep is a signed type[.](#members-1.sentence-2) — *end note*] [🔗](#lib:to_time_t,system_clock) `static time_t to_time_t(const time_point& t) noexcept; ` [2](#members-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2700) *Returns*: A time_t object that represents the same point in time as t when both values are restricted to the coarser of the precisions of time_t andtime_point[.](#members-2.sentence-1) It is implementation-defined whether values are rounded or truncated to the required precision[.](#members-2.sentence-2) [🔗](#lib:from_time_t,system_clock) `static time_point from_time_t(time_t t) noexcept; ` [3](#members-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2716) *Returns*: A time_point object that represents the same point in time as t when both values are restricted to the coarser of the precisions of time_t andtime_point[.](#members-3.sentence-1) It is implementation-defined whether values are rounded or truncated to the required precision[.](#members-3.sentence-2) #### [30.7.2.3](#nonmembers) Non-member functions [[time.clock.system.nonmembers]](time.clock.system.nonmembers) [🔗](#lib:operator%3c%3c,sys_time) `template basic_ostream& operator<<(basic_ostream& os, const sys_time& tp); ` [1](#nonmembers-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2736) *Constraints*: treat_as_floating_point_v is false, andDuration{1} < days{1} is true[.](#nonmembers-1.sentence-1) [2](#nonmembers-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2741) *Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*("{:L%F %T}"), tp); [3](#nonmembers-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2748) [*Example [1](#nonmembers-example-1)*: cout << sys_seconds{0s} << '\n'; // 1970-01-01 00:00:00 cout << sys_seconds{946'684'800s} << '\n'; // 2000-01-01 00:00:00 cout << sys_seconds{946'688'523s} << '\n'; // 2000-01-01 01:02:03 — *end example*] [🔗](#lib:operator%3c%3c,sys_days) `template basic_ostream& operator<<(basic_ostream& os, const sys_days& dp); ` [4](#nonmembers-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2766) *Effects*: os << year_month_day{dp}[.](#nonmembers-4.sentence-1) [5](#nonmembers-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2770) *Returns*: os[.](#nonmembers-5.sentence-1) [🔗](#lib:from_stream,sys_time) `template> basic_istream& from_stream(basic_istream& is, const charT* fmt, sys_time& tp, basic_string* abbrev = nullptr, minutes* offset = nullptr); ` [6](#nonmembers-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2785) *Effects*: Attempts to parse the input stream is into the sys_time tp using the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13 Parsing")[.](#nonmembers-6.sentence-1) If the parse fails to decode a valid date,is.setstate(ios_base​::​failbit) is called andtp is not modified[.](#nonmembers-6.sentence-2) If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null[.](#nonmembers-6.sentence-3) If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null[.](#nonmembers-6.sentence-4) Additionally, the parsed offset will be subtracted from the successfully parsed timestamp prior to assigning that difference to tp[.](#nonmembers-6.sentence-5) [7](#nonmembers-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2802) *Returns*: is[.](#nonmembers-7.sentence-1)