// 방법1
#include <stdio.h>
#include <time.h>
int main ()
{
time_t current_time;
struct tm local_time;
time ( ¤t_time );
localtime_s(&local_time, ¤t_time);
int Year = local_time.tm_year + 1900;
int Month = local_time.tm_mon + 1;
int Day = local_time.tm_mday;
int Hour = local_time.tm_hour;
int Min = local_time.tm_min;
int Sec = local_time.tm_sec;
return 0;
}
// 방법2
#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);
}
참고사이트
참고사이트2