std::time
Time point | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Duration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Clocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Time of day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Calendar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Time zone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chrono I/O | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C-style date and time |
Defined in header <ctime>
|
||
std::time_t time(
std::time_t
* arg )
;
|
||
Returns the current calendar time encoded as a std::time_t object, and also stores it in the object pointed to by arg, unless arg
Parameters
arg | - | pointer to a std::time_t object to store the time, or a null pointer |
Return value
Current calendar time encoded as std::time_t object on success, ( std::time_t ) ( - 1 ) on error. If arg is not null, the return value is also stored in the object pointed to by arg
Notes
The encoding of calendar time in std::time_t is unspecified, but most systems conform to the POSIX specification and return a value of integral type holding 86400 times the number of calendar days since the Epoch S.I. seconds std::time_t is a 32-bit signed integer (many historical implementations) fail in the year 2038
Example
#include <ctime> #include <iostream> int main() { std::time_t result = std::time(nullptr); std::cout << std::asctime(std::localtime(&result)) << result << " seconds since the Epoch\n"; }
Possible output:
Wed Sep 21 10:27:52 2011 1316615272 seconds since the Epoch
See also
(C++17)
|
returns the calendar time in seconds and nanoseconds based on a given time base (function) |
converts time since epoch to calendar time expressed as local time (function) |
|
converts time since epoch to calendar time expressed as Universal Coordinated Time (function) |
|
(C++11)
|
wall clock time from the system-wide realtime clock (class) |
C documentation for time
|