头文件
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-12
cout << to_iso_string(d3) << endl;//20180912
cout << to_iso_extended_string(d4) << endl;//2018-09-12
cout << today.year() << endl;//2018
cout << today.month() << endl;//Sep
cout << today.day() << endl;//12
cout << today.week_number() << endl;//37
cout << today.day_of_week() << endl;//Wed
cout << today.day_of_year() << endl;//255
cout << today.end_of_month() << endl;//2018-Sep-30
日期计算
days ds1(5);
days ds2(-2);
date_duration dd = ds1 + ds2;
cout << dd << endl;//3
cout << dd.days() << endl;//3
weeks ws(1);
cout << ws.days() << endl;//7
cout << dd + ws << endl;//10
months ms(1);
cout << d1 + ms << endl;//2018-Oct-12
years ys(1);
cout << d1 + ys << endl;//2019-Sep-12