std::timespec_get (3) - Linux Manuals
std::timespec_get: std::timespec_get
Command to display std::timespec_get
manual in Linux: $ man 3 std::timespec_get
NAME
std::timespec_get - std::timespec_get
Synopsis
Defined in header <ctime>
int timespec_get( std::timespec* ts, int base) (since C++17)
#define TIME_UTC /* implementation-defined */ (since C++17)
1) Modifies the std::timespec object pointed to by ts to hold the current calendar time in the time base base.
2) Expands to a value suitable for use as the base argument of std::timespec_get
Other macro constants beginning with TIME_ may be provided by the implementation to indicate additional time bases
If base is TIME_UTC, then
* ts->tv_sec is set to the number of seconds since an implementation defined epoch, truncated to a whole value
* ts->tv_nsec member is set to the integral number of nanoseconds, rounded to the resolution of the system clock
Parameters
ts - pointer to an object of type std::timespec
base - TIME_UTC or another nonzero integer value indicating the time base
Return value
The value of base if successful, zero otherwise.
Notes
The POSIX function clock_gettime(CLOCK_REALTIME,_ts) may also be used to populate a std::timespec with the time since the Epoch.
Example
// Run this code
#include <cstdio>
#include <ctime>
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::printf("Current time: %s.%09ld UTC\n", buf, ts.tv_nsec);
}
Possible output:
Current time: 06/24/16 20:07:42.949494132 UTC
See also
timespec time in seconds and nanoseconds
(struct)
(since C++17)
returns the current time of the system as time since epoch
time (function)
Pages related to std::timespec_get
- std::timespec (3) - std::timespec
- std::time (3) - std::time
- std::time_base (3) - std::time_base
- std::time_get (3) - std::time_get
- std::time_get<CharT,InputIt>::date_order,std::time_get<CharT,InputIt>::do_date_order (3) - std::time_get<CharT,InputIt>::date_order,std::time_get<CharT,InputIt>::do_date_order
- std::time_get<CharT,InputIt>::get,std::time_get<CharT,InputIt>::do_get (3) - std::time_get<CharT,InputIt>::get,std::time_get<CharT,InputIt>::do_get
- std::time_get<CharT,InputIt>::get_date,std::time_get<CharT,InputIt>::do_get_date (3) - std::time_get<CharT,InputIt>::get_date,std::time_get<CharT,InputIt>::do_get_date
- std::time_get<CharT,InputIt>::get_monthname, (3) - std::time_get<CharT,InputIt>::get_monthname,
- std::time_get<CharT,InputIt>::get_monthname,std::time_get<CharT,InputIt>::do_get_monthname (3) - std::time_get<CharT,InputIt>::get_monthname,std::time_get<CharT,InputIt>::do_get_monthname
- std::time_get<CharT,InputIt>::get_time,std::time_get<CharT,InputIt>::do_get_time (3) - std::time_get<CharT,InputIt>::get_time,std::time_get<CharT,InputIt>::do_get_time
- std::time_get<CharT,InputIt>::get_weekday,std::time_get<CharT,InputIt>::do_get_weekday (3) - std::time_get<CharT,InputIt>::get_weekday,std::time_get<CharT,InputIt>::do_get_weekday
- std::time_get<CharT,InputIt>::get_year,std::time_get<CharT,InputIt>::do_get_year (3) - std::time_get<CharT,InputIt>::get_year,std::time_get<CharT,InputIt>::do_get_year
- std::time_get<CharT,InputIt>::time_get (3) - std::time_get<CharT,InputIt>::time_get