본문 바로가기

개발 관련 지식/C언어

[C언어] 현재 시간의 마이크로세컨드 구하는 방법

* 현재 시간의 마이크로세컨드 구하는 방법

 

 

[마이크로세컨드 구하는 방법]

#include <time.h>
#include<sys/time.h>

 

void    GetMilSecStr(char *dt)
{
    struct timeval val;
    struct tm *ptm;

 

    gettimeofday(&val, NULL);
    ptm = localtime(&val.tv_sec);

 

    memset(dt , 0x00 , sizeof(dt));

 

    // format : YYMMDDhhmmssuuuuuu
    sprintf(dt, "%04d%02d%02d%02d%02d%02d%06ld"
            , ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday
            , ptm->tm_hour, ptm->tm_min, ptm->tm_sec
            , val.tv_usec);
}