본문 바로가기

개발 관련 지식/C언어

[C언어] 현재 시간의 밀리세컨드 구하는 방법

* 현재 시간의 밀리세컨드 구하는 방법


[밀리세컨드 구하는 방법]

#include <time.h>

#include <sys/timeb.h>


void    GetMilSecStr(char *dt)

{

    struct timeb itb;

    struct tm *lt;


    ftime(&itb);

    lt = localtime(&itb.time);


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


    // format : YYMMDDhhmmssuuuuuu

    sprintf(dt, "%04d%02d%02d%02d%02d%02d%03d"

            , lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday

            , lt->tm_hour, lt->tm_min, lt->tm_sec

            , itb.millitm);