Showing content from https://cplusplus.com/system_clock below:
class
<chrono>
std::chrono::system_clock
System clock
Clock classes provide access to the current time_point.
Specifically, system_clock is a system-wide realtime clock.
Clock properties
-
realtime
-
It is intended to represent the real time, and thus it can be translated in some way to and from calendar representations (see to_time_t and from_time_t member functions).
-
signed count
-
Its time_point values can refer to times before the epoch (with negative values).
-
system-wide
-
All processes running on the system shall retrieve the same time_point values by using this clock.
Member types The following aliases are member types of system_clock:
member type definition notes rep A signed arithmetic type (or a class that emulates it) Used to store a count of periods. period A ratio type Represents the length of a period in seconds. duration duration<rep,period> The clock's duration type. time_point time_point<system_clock> The clock's time_point type.
Member constants member constant definition is_steady a bool value specifying whether the clock always advances, and whether it does at a steady state relative to physical time. If true, this implies that the system clock may not be adjusted.
Static member functions
-
now
-
Get current time (public static member function)
-
to_time_t
-
Convert to time_t (public static member function)
-
from_time_t
-
Convert from time_t (public static member function)
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// system_clock example
#include <iostream>
#include <ctime>
#include <ratio>
#include <chrono>
int main ()
{
using std::chrono::system_clock;
std::chrono::duration<int,std::ratio<60*60*24> > one_day (1);
system_clock::time_point today = system_clock::now();
system_clock::time_point tomorrow = today + one_day;
std::time_t tt;
tt = system_clock::to_time_t ( today );
std::cout << "today is: " << ctime(&tt);
tt = system_clock::to_time_t ( tomorrow );
std::cout << "tomorrow will be: " << ctime(&tt);
return 0;
}
Possible output:
today is: Wed May 30 12:25:03 2012
tomorrow will be: Thu May 31 12:25:03 2012
See also
-
steady_clock
-
Steady clock (class)
-
high_resolution_clock
-
High resolution clock (class)
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4