Program/C & C++

COleDateTime Class

너구리V 2011. 7. 13. 11:43

Windows 프로그램이라면.. COleDateTime Class 를 사용하면된다.

간단하다 생성자는 여러개가 있지만..

간단한 것으로는 6개의 인자를 받으면 된다.

COleDateTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec) 의 값을 주면 된다..

현재의 시간을 받고 싶다면..

COleDateTime thisTime(COleDateTime::GetCurrentTime());

이렇게 하면 되고.

제어는 얻어올 때는 GetYear(), GetMonth() , ~~~ 이 있고.

값을 바꿀 때는 SetDate(int nYear, int nMonth, int nDay), SetTime(int nHour, int nMin, int nSec), SetDateTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec) 등이 있다.

그리고 두 COleDateTime 객체간의 차이를 구할 때는

COleDateTime ATime(2007, 4, 26, 17, 20, 30);
COleDateTime BTime(2007, 4, 26, 18, 20, 50);

COleDateTimeSpan C = BTime - ATime;

C.GetTotalDays() - 차이나는 총 날짜
C.GetTotalHours() - 차이나는 총 시간
C.GetTotalMinutes() - 차이나는 총 분
C.GetTotalSeconds() - 차이나는 총 초

등을 알 수 있다..ㅎㅎ

내용을 추가한다.
CString 으로 바꾸고 싶다면.. 멤버 함수 Format 을 사용하면 된다.

COleDateTime nowTime(COleDateTime::GetCurrentTime());
OutputDebugString(nowTime.Format(_T("%H:%M:%S\n")));

Format 에 들어가는 것은

%a     Abbreviated weekday name
%A     Full weekday name
%b     Abbreviated month name
%B     Full month name
%c     Date and time representation appropriate for locale
%d     Day of month as decimal number (01 – 31)
%H     Hour in 24-hour format (00 – 23)
%I      Hour in 12-hour format (01 – 12)
%j      Day of year as decimal number (001 – 366)
%m    Month as decimal number (01 – 12)
%M   Minute as decimal number (00 – 59)
%p    Current locale's A.M./P.M. indicator for 12-hour clock
%S    Second as decimal number (00 – 59)
%U    Week of year as decimal number, with Sunday as first day of week (00 – 53)
%w   Weekday as decimal number (0 – 6; Sunday is 0)
%W   Week of year as decimal number, with Monday as first day of week (00 – 53)
%x    Date representation for current locale
%X    Time representation for current locale
%y    Year without century, as decimal number (00 – 99)
%Y   Year with century, as decimal number
%z, %Z  Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
%%   Percent sign

반응형

'Program > C & C++' 카테고리의 다른 글

MFC를 이용한 범용 소켓을 이용한 예제  (0) 2011.07.13
MFC를 이용한 범용 서버 소켓 작성  (0) 2011.07.13
Open CV  (0) 2011.04.11
c++콘솔 시계  (0) 2011.03.28
c / c++로 문자열 스택(다중포인터)  (0) 2011.03.28