|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <ctime> | ||
int timespec_get(std::timespec* ts,int base); | (1) | (since C++17) |
#define TIME_UTC /* implementation-defined */ | (2) | (since C++17) |
std::timespec_get.Other macro constants beginning withTIME_ may be provided by the implementation to indicate additional time bases.
Ifbase isTIME_UTC, then
Contents |
| ts | - | pointer to an object of typestd::timespec |
| base | - | TIME_UTC or another nonzero integer value indicating the time base |
The value ofbase if successful, zero otherwise.
The POSIX functionclock_gettime(CLOCK_REALTIME, ts) may also be used to populate astd::timespec with the time since the Epoch.
#include <ctime>#include <iostream> int main(){std::timespec ts; std::timespec_get(&ts, TIME_UTC);char buf[100];std::strftime(buf, sizeof buf,"%D %T",std::gmtime(&ts.tv_sec));std::cout<<"Current time: "<< buf<<'.'<< ts.tv_nsec<<" UTC\n";}
Possible output:
Current time: 06/24/16 20:07:42.949494132 UTC
(C++17) | time in seconds and nanoseconds (struct)[edit] |
| returns the current time of the system as time since epoch (function)[edit] | |
C documentation fortimespec_get | |