这是我最喜欢的日期类(仅限C++,而不是C):
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
}
Run Code Online (Sandbox Code Playgroud)
该软件可免费使用.你甚至不必信任任何人.1个标题,1个来源.
更新
该软件的最新版本如下:https://howardhinnant.github.io/date/date.html