python设计一个date类数据成员有年月日_1.设计一个日期类date,其中包含年、月、日等数据成员。要求实现日期的基本运算,如一日期加上天数、或减...

展开全部

// Date.h: interface for the CFCWorldDate class.

//

//

#if !defined(AFX_DATE_H__FF59967B_C0A3_4CF9_9054_8578E83FF3BD__INCLUDED_)

#define AFX_DATE_H__FF59967B_C0A3_4CF9_9054_8578E83FF3BD__INCLUDED_

#include

#include

#ifdef HAVE_UNISTD_H

#include

#endif

#include

#include

class CDateTime

{

struct _FORMAT

{

int local;

std::string Key;

};

public:

long m_lTime;

int m_iYear;

int m_iMonth;

int m_iDay;

int m_iHour;

int m_iMinute;

int m_iSecond;

int m_iWeek;

int m_iDiff;//UTC与LOCAL时间之间所差的秒数,用本地时间减去UTC时间

bool m_bLocal;

public:

//得到一个月的天数

int DaysInMonth();

//判断是否为润年

bool isLeapYear();

CDateTime(bool bLocal= false);//false表示构造32313133353236313431303231363533e59b9ee7ad9431333262376666的UTC时间,它构造的当前时间

CDateTime(int iYear,int iMonth,int iDay,int iHour,int iMinute,int iSecond,bool bLocal= false);//默认产生UTC时间

virtual ~CDateTime();

void Today(bool bLocal= false);//得到当前日期,默认产生UTC时间

int GetYear() {return m_iYear;}

int GetMonth(){ return m_iMonth ;}

int GetDay() { return m_iDay;}

int GetWeek() {return m_iMonth;}

CDateTime& AddYears(int iValue);

CDateTime& AddMonths(int iValue);

CDateTime& AddDays(int iValue);

CDateTime& AddWeeks(int iValue);

CDateTime& AddHours(int iValue);

CDateTime& AddMinutes(int iValue);

CDateTime& AddSeconds(int iValue);

//比较时间大小,如果比OtherDate大,返回1,如果相等,返回0,如果小于,返回-1

int Compare(CDateTime& OtherDate);

//格式化时间

std::string ToString(std::string sFormat="YYYY-MM-DD HH:MI:SS");

CDateTime StringToTime(std::string sDate,std::string sFormat="YYYY-MM-DD HH:MI:SS");

//把时间从UTC到本地时间转换

CDateTime& UTCToLocalTime();

//把时间从本地到UTC时间转换

CDateTime& LocalToUTCTime();

//得到两个时间相差的秒数

long operator-(CDateTime& DT);

private:

int GetWeekFromLongTime();

void ToTime(long lDate);

long ToLong();

};

#endif // !defined(AFX_DATE_H__FF59967B_C0A3_4CF9_9054_8578E83FF3BD__INCLUDED_)

// Date.cpp: implementation of the CDateTime class.

//

//

#include "DateTime.h"

#include

//

// Construction/Destruction

//

const char *dayname[] = {"Sunday","Monday","Tuesday","Wednesday",

"Thursday","Friday","Saturday"} ;

const char *mname[] = {"January","February","March","April","May",

"June","July","August","September","October","November","December"};

static int MonDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

CDateTime::CDateTime(bool bLocal)

{

m_bLocal = bLocal;

Today(bLocal);

}

CDateTime::~CDateTime()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值