반응형
/*** 컴파일시에 -lrt 를 포함하여 컴파일 ***/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(int argc, char *argv[])
{
struct timespec tspec;
struct tm tm_now;
clock_gettime(CLOCK_REALTIME, &tspec);
localtime_r((time_t *)&tspec.tv_sec, &tm_now);
fprintf(stdout, "timespec tspec.tv_sec=%ld tspec.tv_nsec=%09ld\n", tspec.tv_sec, tspec.tv_nsec);
fprintf(stdout, "%04d%02d%02d%02d%02d%02d.%09ld\n", tm_now.tm_year + 1900, tm_now.tm_mon + 1, tm_now.tm_mday, tm_now.tm_hour, tm_now.tm_min, tm_now.tm_sec, tspec.tv_nsec);
}
실행결과
timespec tspec.tv_sec=1451288985 tspec.tv_nsec=200300400
20151228164945.200300400
반응형