头文件
boost/date_time/gregorian/gregorian.hpp
date类
//获取今天的如期date today = day_clock::local_day();//日期初始化date d1(2018, 9, 12);date d2 = from_string(\"2018-09-12\");date d3 = from_string(\"2018/09/12\");date d4 = from_undelimited_string(\"20180912\");//month,week返回的是英文字符串,需要用as_number获取数字cout << d1.year() << \"年\" << d1.month().as_number() << \"月\" << d1.day() << \"日\" << endl;//2018年9月12日cout << to_simple_string(d2) << endl;//2018-Sep-12cout << to_iso_string(d3) << endl;//20180912cout << to_iso_extended_string(d4) << endl;//2018-09-12cout << today.year() << endl;//2018cout << today.month() << endl;//Sepcout << today.day() << endl;//12cout << today.week_number() << endl;//37cout << today.day_of_week() << endl;//Wedcout << today.day_of_year() << endl;//255cout << today.end_of_month() << endl;//2018-Sep-30
日期计算
days ds1(5);days ds2(-2);date_duration dd = ds1 + ds2;cout << dd << endl;//3cout << dd.days() << endl;//3weeks ws(1);cout << ws.days() << endl;//7cout << dd + ws << endl;//10months ms(1);cout << d1 + ms << endl;//2018-Oct-12years ys(1);cout << d1 + ys << endl;//2019-Sep-12