std::timespec(3)
π NAME π
okay bestie, welcome to std::timespec(3) from the C++ Standard Libary (sic β their spelling, not mine π). The NAME section is literally:
std::timespec - std::timespec
...and yes, that's the whole thing ππ .
πΈ Synopsis πΈ
Defined in header <ctime>:
Defined in header <ctime>
struct timespec; (since C++17)
This icon is since C++17 β¨. It's a structure holding an interval broken down into seconds and nanoseconds. π°οΈ
π Member objects π
std::time_t tv_secβ whole seconds β>= 0β±οΈlong tv_nsecβ nanoseconds β[0, 999999999]β‘
The declaration order of tv_sec and tv_nsec is unspecified. π Implementation may add other data members to timespec. No cap.
π¨ Notes π¨
The type of tv_nsec is long long on some platforms, which is currently non-conforming in C++, but is allowed in C since C23. π So yeah, platform vibes.
π» Example π»
The page says // Run this code πββοΈπ¨:
#include <ctime>
#include <iostream>
int main()
{
std::timespec ts;
std::timespec_get(&ts, TIME_UTC);
char buff[0x80];
std::strftime(buff, sizeof buff, "%D %T", std::gmtime(&ts.tv_sec));
// auto [sec, nsec] = ts; // UB: structured bindings should not be
used because the
// declaration order and data member list
are unspecified
std::cout << "Current time: " << buff << " (UTC)\n"
<< "Raw timespec.tv_sec: " << ts.tv_sec << '\n'
<< "Raw timespec.tv_nsec: " << ts.tv_nsec << '\n';
}
β¨ Possible output β¨
Current time: 04/06/23 12:03:31 (UTC)
Raw timespec.tv_sec: 1680782611
Raw timespec.tv_nsec: 678437213
π See also π
timespec_getβ returns the calendar time in seconds and nanoseconds based on a given time base (C++17) (function) π₯tmβ calendar time type (class) ποΈ- C documentation for
timespecπ
source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::timespec(3) β slay, bestie, that's the whole page π
β¨
π¦ 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