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

📄 date.h

📁 C++时间类
💻 H
字号:

#define DOSDATE_T   dosdate_t


#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <iostream>


#define MEMBER
#define ABBR_LENGTH 3
using namespace std;
struct   dosdate_t      
{                                                
   int   year;   /*自1900的年数*/
   int   day;   /*天数*/            
   int   month;   /*月数   1=Jan*/ 
};
class Date
{
    public:
        //
        // TML - Put into class so we don't proliferate global names...in the
        //       tradition of the 'ios' class!
        //       Make use of the encapsulation feature of C++
        //
         enum format_type {MDY, DAY, MONTH, FULL, EUROPEAN};
         enum {OFF, ON};
         enum {BUF_SIZE=40};
         enum { NO_CENTURY  = (unsigned char) 0x02,
                     DATE_ABBR   = (unsigned char) 0x04};

    protected:
        unsigned long julian;       // see julDate();  days since 1/1/4713 B.C.
        int year;                   // see NYear4()
		int month;		// see NMonth()
        int day;          // see Day()
		int day_of_week;	// see NDOW();	1 = Sunday, ... 7 = Saturday

	private:
		static int DisplayFormat;
		static int DisplayOptions;
        static char cbuf[BUF_SIZE];     // Date::formatDate()'s buffer space

        void julian_to_mdy ();          // convert julian day to mdy
        void julian_to_wday ();         // convert julian day to day_of_week
        void mdy_to_julian ();          // convert mdy to julian day

	public:
		Date ();
        Date (long j);
        Date (int m, int d, int y);
        Date (const char * dat);
        Date (const DOSDATE_T &ds);
		Date (const Date &dt);
        virtual ~Date() {}              // Do nothing!

        operator char *( void );        // Date to character - via type casting

        Date  operator + (long i);
        Date  operator + (int i);

        Date  operator - (long i);
        Date  operator - (int i);
        long  operator - (const Date &dt);

        const Date &operator += (long i);
        const Date &operator -= (long i);

        Date  operator ++ ();               // Prefix increment
        Date  operator ++ (int);            // Postfix increment
        Date  operator -- ();               // Prefix decrement
        Date  operator -- (int);            // Postfix decrement

        int operator <  (const Date &dt);   // TML - Convert to member
        int operator <= (const Date &dt);   // functions from 'friend'
        int operator >  (const Date &dt);   // functions
        int operator >= (const Date &dt);
        int operator == (const Date &dt);
        int operator != (const Date &dt);

        friend ostream &operator << (ostream &os, const Date &dt);
        friend ostream &operator << (ostream &os, const DOSDATE_T &dt);

        const  char * formatDate(int type=DisplayFormat) const;
        static void   setFormat (int format);
        static int    setOption (int option, int action=ON);

		long  julDate() 	const;	// returns julian date
        int   DOY()         const;  // returns relative date since Jan. 1
		int   isLeapYear()	const;	// returns 1 if leap year, 0 if not

		// note that the next functions return a date struct as defined in
		// dos.h (distinct from the Date class)

        DOSDATE_T  eom()        const;  // returns last day of month in object
        DOSDATE_T  getDate()    const;  // returns a date structure



        // These 'Set's modify the date object and actually SET it
		// They all return a reference to self (*this)

        const Date &Set();                    // Sets to current system date
        const Date &Set(long lJulian);
        const Date &Set(int nMonth, int nDay, int nYear);

        const Date &AddWeeks(int nCount = 1);  //
        const Date &AddMonths(int nCount = 1); // May also pass neg# to 
        const Date &AddYears(int nCount = 1);  // decrement

        int Day() const;        // Numeric Day of date object

        int DaysInMonth();      // Number of days in month (1..31)

        int FirstDOM() const;   // First Day Of Month  (1..7)

        const char *CDOW();     // Character Day Of Week ('Sunday'..'Saturday')
        int NDOW() const;       // (1..7)

        int WOM();              // Numeric Week Of Month  (1..6)
        int WOY();              // Numeric Week Of Year   (1..52)

        const char * CMonth();  // Character Month name
		int  NMonth() const;	// Month Number (1..12)
        Date BOM();             // First Date Of Month
        Date EOM();             // Last Date Of Month

		int  NYear4() const;	// eg. 1992
        Date BOY();             // First Date Of Year
        Date EOY();             // Last Date Of Year
};





⌨️ 快捷键说明

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