본문 바로가기

C++ in Windows/MFC

CTime


MSDN - CTime Members (클릭)

나는 주로 아래와 같이 사용한다.
CTime tTime(CTime::GetCurrentTime());
CString str;

// 시간을 형식에 맞게 출력할때나.
str.Format(L"%4d-%2d-%2d", tTime.GetYear(), tTime.GetMonth(), tTime.GetDay());

// __int64로 만들어 파일에 저장한다 던가.
int iTime = tTime.GetTime();

// __int64을 읽어 프로그램 내에서 사용한다던가.
CTime setTime(iTime);
아래는 crtdefs.h에 있는 CTime 클래스이다.
class CTime
{
public:
	static CTime WINAPI GetCurrentTime() throw();
	static BOOL WINAPI IsValidFILETIME(const FILETIME& ft) throw();

	CTime() throw();
	CTime( __time64_t time ) throw();
	CTime( int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,
		int nDST = -1 );
	CTime( WORD wDosDate, WORD wDosTime, int nDST = -1 );
	CTime( const SYSTEMTIME& st, int nDST = -1 );
	CTime( const FILETIME& ft, int nDST = -1 );
#ifdef __oledb_h__
	CTime( const DBTIMESTAMP& dbts, int nDST = -1 ) throw();
#endif

	CTime& operator=( __time64_t time ) throw();

	CTime& operator+=( CTimeSpan span ) throw();
	CTime& operator-=( CTimeSpan span ) throw();

	CTimeSpan operator-( CTime time ) const throw();
	CTime operator-( CTimeSpan span ) const throw();
	CTime operator+( CTimeSpan span ) const throw();

	bool operator==( CTime time ) const throw();
	bool operator!=( CTime time ) const throw();
	bool operator<( CTime time ) const throw();
	bool operator>( CTime time ) const throw();
	bool operator<=( CTime time ) const throw();
	bool operator>=( CTime time ) const throw();

	struct tm* GetGmtTm( struct tm* ptm ) const;
	struct tm* GetLocalTm( struct tm* ptm ) const;

	bool GetAsSystemTime( SYSTEMTIME& st ) const throw();
#ifdef __oledb_h__
	bool GetAsDBTIMESTAMP( DBTIMESTAMP& dbts ) const throw();
#endif

	__time64_t GetTime() const throw();

	int GetYear() const throw();
	int GetMonth() const throw();
	int GetDay() const throw();
	int GetHour() const throw();
	int GetMinute() const throw();
	int GetSecond() const throw();
	int GetDayOfWeek() const throw();

	// formatting using "C" strftime
	CString Format( LPCTSTR pszFormat ) const;
	CString FormatGmt( LPCTSTR pszFormat ) const;
	CString Format( UINT nFormatID ) const;
	CString FormatGmt( UINT nFormatID ) const;

#if defined(_AFX) && defined(_UNICODE) && !defined(_WIN32_WCE)
// for compatibility with MFC 3.x
	CString Format(LPCSTR pFormat) const;
	CString FormatGmt(LPCSTR pFormat) const;
#endif // _AFX && _UNICODE && !_WIN32_WCE

#ifdef _AFX
#ifndef _WIN32_WCE_NO_ARCHIVE_SUPPORT
	CArchive& Serialize64(CArchive& ar);
#endif // _WIN32_WCE_NO_ARCHIVE_SUPPORT
#endif

private:
	__time64_t m_time;
};

'C++ in Windows > MFC' 카테고리의 다른 글

CFile, CFileException  (0) 2012.01.12
CString <-> int  (0) 2012.01.12