⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 date.h

📁 API经典入门
💻 H
字号:
#ifndef __DATE_H__
#define __DATE_H__

#ifndef __SQL
typedef unsigned short int UWORD;
typedef short int SWORD;
#endif
 
class CDate : public CObject
{

DECLARE_SERIAL(CDate)

protected:

	SWORD m_nYear;
	UWORD m_nMonth;
	UWORD m_nDay;

public:
    
    // constructors
	CDate(); // default
	//default constructor initializes date to null
	CDate(CDate& Date);  // copy 
	CDate(CTime& Time);
    CDate(SWORD y, UWORD m, UWORD d);
	
	// assignment
	CDate& operator=(CDate& Date);
	
	// selectors
	SWORD Year()
		{return m_nYear;}
	UWORD Month()
		{return m_nMonth;}
	UWORD Day()
		{return m_nDay;}

	// functions that increment the date by one day
	CDate& operator++();	// prefix notation
	CDate& operator++(int);	// postfix notation
	void AddDay();

	// functions that decrement the date by one day
	CDate& operator--();	// prefix notation
	CDate& operator--(int);	// postfix notation
	void SubtractDay();

protected:	
	// internal month increments.
	// these functions don't validate the day!
	void AddMonth();
	void SubtractMonth();

public:
	// sum & difference operators
	CDate& operator+ (unsigned int Days);
	CDate& operator- (unsigned int Days);
	int operator- (CDate& Date);  // returns days
	void Subtract (CDate& Date, UWORD& Years,
			UWORD& Months, UWORD& Days); 
	// returns difference in Years, Months, and Days
	void Add (SWORD Years, SWORD Months = 0, SWORD Days = 0);
	
	// comparison operators
	BOOL operator== (CDate& Date);
	BOOL operator!= (CDate& Date);
	BOOL operator> (CDate& Date);
	BOOL operator>= (CDate& Date);
	BOOL operator< (CDate& Date);
	BOOL operator<= (CDate& Date);

	// returns FALSE if Date is invalid
	BOOL IsValid();
	
	// changes date to closest valid date
	void MakeValid();
	
	// returns TRUE if leapyear
	BOOL IsLeapYear(SWORD y);
	
	// returns the number of days in the month
	UWORD DaysInMonth();

	// returns a CString object representation of the date.
	// Format is the same as in strftime() -- see MS Visual C++
	// run-time library reference.
	CString DateString (const char* Format = "%d %b %Y");
	
	// sets the date to the value held in the string
	// a string to date conversion is performed.
	// Returns TRUE if successful.
	BOOL StringToDate (const char* strDate);
			
#ifdef _DEBUG
	virtual void Dump(CDumpContext& dc) const;
	virtual void AssertValid() const;
#endif 

	virtual void Serialize( CArchive& ar);

};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -