std::timespec_get(3)
π std::timespec_get(3) π
Ok bestie, this page is from the C++ Standard Libary β yes, thatβs the spelling in the header, and weβre keeping it π. Manual name: std::timespec_get(3). Letβs get into it. π
β¨ NAME β¨
std::timespec_get - std::timespec_get. Literally the name repeats, and honestly? Iconic. π
πΈ Synopsis πΈ
Defined in header <ctime> β thatβs where this cutie lives.
int timespec_get( std::timespec* ts, int base ); (1) (since C++17)
#define TIME_UTC /* implementation-defined */ (2) (since C++17)
Now the deets, bestie:
- Modifies the
std::timespecobject pointed to bytsto hold the current calendar time in the time basebase. - Expands to a value suitable for use as the
baseargument ofstd::timespec_get.
Other macro constants beginning with TIME_ may be provided by the implementation to indicate additional time bases. Keep an eye out π
If base is TIME_UTC, then:
ts->tv_secis set to the number of seconds since an implementation defined epoch, truncated to a whole value,ts->tv_nsecmember 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_UTCor another nonzero integer value indicating the time base
π« Return value π«
It gives you back the value of base if successful, and zero otherwise. Simple, clean, slay. β¨
π¦ Notes π¦
The POSIX function clock_gettime(CLOCK_REALTIME, ts) may also be used to populate a std::timespec with the time since the Epoch. iykyk π«Ά
π Example π
// Run this code β go off, bestie:
#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
π See also π
timespecβ time in seconds and nanoseconds (C++17) (struct)timeβ returns the current time of the system as time since epoch (function)- C documentation for
timespec_get
π Thatβs the whole page, bestie β source/version: http://cppreference.com; date: 2024.06.10; manual: std::timespec_get(3). Mwah! π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms