MFC는 다음과 같은 코드로 가능하다.
SYSTEMTIME cur;
GetLocalTime(&cur);//GetSystemTime(&cur);
req.wYear = cur.wYear;
req.wMonth = cur.wMonth;
req.wDay = cur.wDay;
req.wHour = cur.wHour;
req.wMinute = cur.wMinute;
req.wSecond = cur.wSecond;
req.wDayOfWeek = cur.wDayOfWeek;
유닉스 C (posix C 겠지?) 에서는 다음과 같이 가능하다.
#include
void main(void)
{
time_t timer;
struct tm *t;
timer = time(NULL); // 현재 시각을 초 단위로 얻기
t = localtime(&timer); // 초 단위의 시간을 분리하여 구조체에 넣기
printf("현재 년: %d\n", t->tm_year + 1900);
printf("현재 월: %d\n", t->tm_mon + 1);
printf("현재 일: %d\n\n", t->tm_mday);
printf("현재 시: %d\n", t->tm_hour);
printf("현재 분: %d\n", t->tm_min);
printf("현재 초: %d\n\n", t->tm_sec);
printf("현재 요일: %d\n", t->tm_wday); // 일요일=0, 월요일=1 ...
}
자세한 구조체 선언은 스스로 뒤벼보센 : )
Ref :
1. http://mwultong.blogspot.com/2006/10/c-current-date-time.html
2. http://mwultong.blogspot.com/2006/10/c-timeh-struct-tm-time-structure.html
3. 내가 보고있던 어떤 소스.
PS. 출력값이 동일할거라고 생각되지만, 아닐수도 있음. (테스트 안해봤음)
SYSTEMTIME cur;
GetLocalTime(&cur);//GetSystemTime(&cur);
req.wYear = cur.wYear;
req.wMonth = cur.wMonth;
req.wDay = cur.wDay;
req.wHour = cur.wHour;
req.wMinute = cur.wMinute;
req.wSecond = cur.wSecond;
req.wDayOfWeek = cur.wDayOfWeek;
유닉스 C (posix C 겠지?) 에서는 다음과 같이 가능하다.
#include
void main(void)
{
time_t timer;
struct tm *t;
timer = time(NULL); // 현재 시각을 초 단위로 얻기
t = localtime(&timer); // 초 단위의 시간을 분리하여 구조체에 넣기
printf("현재 년: %d\n", t->tm_year + 1900);
printf("현재 월: %d\n", t->tm_mon + 1);
printf("현재 일: %d\n\n", t->tm_mday);
printf("현재 시: %d\n", t->tm_hour);
printf("현재 분: %d\n", t->tm_min);
printf("현재 초: %d\n\n", t->tm_sec);
printf("현재 요일: %d\n", t->tm_wday); // 일요일=0, 월요일=1 ...
}
자세한 구조체 선언은 스스로 뒤벼보센 : )
Ref :
1. http://mwultong.blogspot.com/2006/10/c-current-date-time.html
2. http://mwultong.blogspot.com/2006/10/c-timeh-struct-tm-time-structure.html
3. 내가 보고있던 어떤 소스.
PS. 출력값이 동일할거라고 생각되지만, 아닐수도 있음. (테스트 안해봤음)


덧글
이지영 2009/03/03 18:40 # 삭제 답글
저런건 그냥 시계를 보면 되는거 아닐까?
승네군 2009/03/03 18:49 # 답글
어? 굳드 아이디어!@.@
나쯔 2009/03/08 16:19 # 답글
int GetDateTime( char *pCurDateTime ){
time_t csec;
struct tm *stTime;
csec = time (NULL);
stTime = localtime(&csec);
if (stTime == NULL)
return ( FALSE );
sprintf (pCurDateTime, "%04d%02d%02d%02d%02d%02d",
stTime->tm_year+1900, stTime->tm_mon+1, stTime->tm_mday,
stTime->tm_hour, stTime->tm_min, stTime->tm_sec);
return ( TRUE );
}
이렇게 해놓고 불러다 써.
승네군 2009/03/09 09:06 # 삭제 답글
아, 시간을 문자열로 얻어내고 싶은건 아니였고, 윈도우용 프로그램을 맥으로 포팅하는데.. 시간 관련된 내용이 나와서... 찾다보니 똑같은 역할을 하는 함수가 있길래 가져왔음 : )Anyway, Thx : )