如何比较C/C++中的日期范围?

2024-04-24

C/C++ 中是否有系统定义的函数来比较两个日期?

Thanks


这是我最喜欢的日期类(仅限 C++,不是 C):

http://howardhinnant.github.io/date.html http://howardhinnant.github.io/date.html

这样你就可以编写如下程序:

#include "date.h"
#include <cassert>

int main()
{
    using namespace gregorian;
    date d1 = thu[last]/mar/2011; // last Thursday in March 2011
    date d2 = mar/31/2011;       // March 31, 2011
    assert(d1 == d2);            // The last Thursday in March 2011 is 3/31/2011
    d1 += month(1);              // last Thursday in April 2011
    assert(d1 > d2);             // d1 is later than d2
    assert(d1 == month(4)/28/2011); // d1 is now Apr. 28, 2011
}

该软件可以免费使用。你甚至不必相信任何人。 1header http://home.roadrunner.com/~hinnant/date.h, 1 source http://home.roadrunner.com/~hinnant/date.cpp.

Update

该软件的最新版本在这里:https://howardhinnant.github.io/date/date.html https://howardhinnant.github.io/date/date.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何比较C/C++中的日期范围? 的相关文章

随机推荐