반응형
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
int main()
{
struct timeval now;
struct tm *pLocalTime;
char sDateTime[128];
/* 현재 시간을 얻어온다. */
gettimeofday(&now, NULL);
pLocalTime = (struct tm*)localtime((time_t*)&now.tv_sec);
/*데이트의 형식 변환 */
memset(sDateTime, 0x00, sizeof(sDateTime));
sprintf(sDateTime, "%04d-%02d-%02d %02d:%02d:%02d.%03d", pLocalTime->tm_year+1900, pLocalTime->tm_mon+1, pLocalTime->tm_mday, pL
ocalTime->tm_hour, pLocalTime->tm_min, pLocalTime->tm_sec, now.tv_usec/1000 );
printf("CurrentDateTimeMillisec:%s\n", sDateTime);
return 0;
}
반응형