Post List

2014년 12월 25일 목요일

[MFC] 현재시간 구하기

원문 : http://blog.naver.com/scoolde/130175573216

현재 타임 구하기

현재시간을 구하는 방법에도 여러가지가 있다.
 MFC에서 제공해주는 API,  C에서 사용할 수 있는 time 등 차근차근 Time에 관련되어 현재 시간을 구하고,
최대 밀리세컨드 또는 정확한 타이머를 위하여 정리 하였다.

현재 시간 구하기 목록
1. CTime
2. SYSTEMTIME

1. cTime
 
CTime thetime;
thetime = CTime::GetCurrentTime();

CString str;
출력
str.Format(" %d, %d, %d \n", thetime.GetHour(), thetime.GetMinute(), thetime.GetSecond());
 
01//현재시간 구하기
02SYSTEMTIME curTime;
03GetLocalTime(&curTime);
04CString strCurTime;
05strCurTime.Format("%d년 %d월 %d일 %d:%d:%d ", curTime.wYear, curTime.wMonth, curTime.wDay, curTime.wHour, curTime.wMinute, curTime.wSecond);
06 
07//SYSTEMTIME 구조체 정보
08typedef struct _SYSTEMTIME {
09 WORD wYear;
10  WORD wMonth;
11  WORD wDayOfWeek;
12  WORD wDay;
13  WORD wHour;
14  WORD wMinute;
15  WORD wSecond;
16  WORD wMilliseconds;
17} SYSTEMTIME;



C에서 현재 시간 구하기

#include <stdio.h>
#include <time.h>

int main( void)
{
   time_t   current_time;

   time( &current_time);

   printf( "%ldn", current_time);
   printf( ctime( &current_time));

   return 0;
}
]$ ./a.out
1184746481
Wed Jul 18 17:14:41 2007
]$

댓글 없음:

댓글 쓰기