Namespaces
Variants

timespec_getres

From cppreference.net
헤더 파일에 정의됨 <time.h>
int timespec_getres ( struct timespec * ts, int base ) ;
(C23 이후)

만약 ts 가 null이 아니고 base timespec_get 에 의해 지원되는 경우, * ts 를 수정하여 timespec_get base 에 대해 제공하는 시간의 해상도를 저장합니다. 지원되는 각 base 에 대해, 동일한 프로그램 실행 중에 timespec_getres 를 여러 번 호출해도 동일한 결과를 얻습니다.

목차

매개변수

ts - struct timespec 타입의 객체를 가리키는 포인터
base - TIME_UTC 또는 시간 기준을 나타내는 0이 아닌 다른 정수 값

반환값

base 가 지원되는 경우 base 의 값, 그렇지 않으면 0입니다.

참고 사항

POSIX 함수 clock_getres(clock_id, ts) timespec clock_id 로 식별되는 시간의 해상도로 채우는 데에도 사용될 수 있습니다.

예제

#include <stdio.h>
#include <time.h>
int main(void)
{
    char buff[128];
    struct timespec ts;
    const int res = timespec_getres(&ts, TIME_UTC);
    if (res == TIME_UTC) {
        struct tm timer;
        strftime(buff, sizeof buff, "%D %T", gmtime_r(&ts.tv_sec, &timer));
        printf("Time resolution info: %s.%09ld UTC\n", buff, ts.tv_nsec);
    } else {
        printf("TIME_UTC base is not supported.");
    }
}

가능한 출력:

Time resolution info: 01/01/70 00:00:00.000000001 UTC

참고 항목

초와 나노초 단위의 시간
(구조체)
주어진 시간 기준에 따른 달력 시간을 초와 나노초 단위로 반환
(함수)
시스템의 현재 달력 시간을 에포크 이후 시간으로 반환
(함수)