c++比较日期如何做

wan766405890 2011-12-27 04:09:45
要求这样
起始日期<当前日期 结束日期>当前日期
返回bool值就行
c++确实不懂
...全文
324 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
柯本 2011-12-28
  • 打赏
  • 举报
回复
将日期格式化成yyyy-mm-dd(如2011-02-05),然后直接用strcmp就可以了
wan766405890 2011-12-28
  • 打赏
  • 举报
回复
谢谢楼上的答复,但是我不是要这样的东西,而是代码
赵4老师 2011-12-27
  • 打赏
  • 举报
回复
COleDateTime Relational Operators
BOOL operator ==( const COleDateTime& date ) const;
BOOL operator !=( const COleDateTime& date ) const;
BOOL operator <( const COleDateTime& date ) const;
BOOL operator >( const COleDateTime& date ) const;
BOOL operator <=( const COleDateTime& date ) const;
BOOL operator >=( const COleDateTime& date ) const;

Remarks

These operators compare two date/time values and return nonzero if the condition is true; otherwise 0.

Note The return value of the ordering operations (<, <=, >, >=) is undefined if the status of either operand is null or invalid. The equality operators (==, !=) consider the status of the operands.

Example

COleDateTime dateOne(95, 3, 15, 12, 0, 0); // 15 March 1995 12 noon
COleDateTime dateTwo(dateOne); // 15 March 1995 12 noon
BOOL b;
b = dateOne == dateTwo; // TRUE

dateTwo.SetStatus(COleDateTime::invalid);
b = dateOne == dateTwo; // FALSE, different status
b = dateOne != dateTwo; // TRUE, different status
b = dateOne < dateTwo; // FALSE, same value
b = dateOne > dateTwo; // FALSE, same value
b = dateOne <= dateTwo; // TRUE, same value
b = dateOne >= dateTwo; // TRUE, same value

Note The last four lines of the preceding example will ASSERT in debug mode.

COleDateTime Overview | Class Members | Hierarchy Chart

See Also COleDateTime::GetStatus
赵4老师 2011-12-27
  • 打赏
  • 举报
回复
COleDateTime
篾匠 2011-12-27
  • 打赏
  • 举报
回复
年、月、日一个一个地比较就行了嘛

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧