date.cpp
来自「有计算机图形学、图像处理、dbms、sniffer、中游俄罗斯外挂、othell」· C++ 代码 · 共 121 行
CPP
121 行
// Date.cpp: implementation of the Date class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Database.h"
#include "Date.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Date::Date()
{
tag=year=month=day=0;
}
Date::Date(WORD y,WORD m,WORD d,WORD t)
{
int mark[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(y>=0&&y<10000)
{
year=y;
if(y%400==0||(y%4==0&&y%100!=0))
mark[2]=29;
}
if(m>=1&&m<13)
month=m;
if(d>0&&d<=mark[m])
day=d;
tag=t;
}
Date::Date(CString s)
{
if(s.GetLength()==10&&s[4]=='-'&&s[7]=='-')
{
year=WORD(atoi(LPCTSTR(s.Left(4))));//未考虑范围
month=WORD(atoi(LPCTSTR(s.Mid(5,2))));
day=WORD(atoi(LPCTSTR(s.Right(2))));
tag=TRUE;
}
else
{
AfxMessageBox("format wrong");
}
}
int Date::operator -(const Date &d)
{
return 0;
}
bool Date::operator <(const Date &d)
{
if(year<d.year||(year==d.year&&month<d.month)||(year==d.year&&month==d.month&&day<d.day))
return TRUE;
else return FALSE;
}
bool Date::operator <=(const Date &d)
{
if(year<d.year||(year==d.year&&month<d.month)||(year==d.year&&month==d.month&&day<=d.day))
return TRUE;
else return FALSE;
}
bool Date ::operator >(const Date &d)
{
if(year>d.year||(year==d.year&&month>d.month)||(year==d.year&&month==d.month&&day>d.day))
return TRUE;
else return FALSE;
}
bool Date ::operator >=(const Date &d)
{
if(year>d.year||(year==d.year&&month>d.month)||(year==d.year&&month==d.month&&day>=d.day))
return TRUE;
else return FALSE;
}
bool Date::operator ==(const Date &d)
{
if(year==d.year && month==d.month && day==d.day)
return TRUE;
else return FALSE;
}
CString Date::DateToCString()
{
CString result;
CString temp;
result.Format("%d",year);
if(year<1000)
result="0"+result;
result=result+"-";
temp.Format("%d",month);
if(month<10)
temp="0"+temp;
result=result+temp+"-";
temp.Format("%d",day);//可能有问题
if(day<10)
temp="0"+temp;
result=result+temp;
return result;
}
Date::~Date()
{
}
Date::Date(const Date &date)
{
this->tag=date.tag;
this->year=date.year;
this->month=date.month;
this->day=date.day;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?