std:: timespec
From cppreference.net
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더에 정의됨
<ctime>
|
||
|
struct
timespec
;
|
(C++17부터) | |
초와 나노초로 분해된 시간 간격을 보유하는 구조체.
목차 |
데이터 멤버
| 멤버 | 설명 |
|
std::time_t
tv_sec
|
전체 초, 값은 >=
0
(public member object) |
|
long
tv_nsec
|
나노초, 값의 범위는
[
0
,
999999999
]
(public member object) |
tv_sec
와
tv_nsec
의 선언 순서는 명시되지 않습니다. 구현에서는
timespec
에 다른 데이터 멤버를 추가할 수 있습니다.
참고 사항
tv_nsec
의 타입은 일부 플랫폼에서
long
long
입니다. 이는 현재 C++에서는 표준을 따르지 않지만, C23부터는 C에서 허용됩니다.
예제
이 코드 실행
#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'; }
가능한 출력:
Current time: 04/06/23 12:03:31 (UTC) Raw timespec.tv_sec: 1680782611 Raw timespec.tv_nsec: 678437213
참고 항목
|
(C++17)
|
주어진 시간 기준을 기반으로 초와 나노초 단위의 캘린더 시간을 반환합니다
(함수) |
|
캘린더 시간 타입
(클래스) |
|
|
C documentation
for
timespec
|
|