c++比较日期 技能
c++比较日期 技巧
基本思想是:
将日期转化成字符串,通过字符串的比较,比较出日期
代码实现:
bool Date::operator<(const Date& rhs)
{
stringstream strstream, stristream;
strstream << year << month << day << hour << minute << second;
string date = strstream.str();
stristream << rhs.getYear() << rhs.getMonth() << rhs.getDay() << rhs.getHour() << rhs.getMinute() << rhs.getSecond();
string newDate = stristream.str();
if(date.compare(newDate) < 0)
{
return true;
}
else
{
return false;
}
}