// DateTime.cpp : 定义控制台应用程序的入口点。 // #include <string> #include <iostream> using namespace std; #include <boost/date_time.hpp> using namespace boost::gregorian; //using namespace boost::gregorian; //using namespace boost; int main() { // 定义日期 date myDate(2013,6,1); cout << to_iso_string(myDate) << endl; date myOtherDate = from_undelimited_string("20130601"); // 获取年月日 int nYear = myDate.year(); int nMonth = myDate.month(); int nDay = myDate.day(); cout << "年" << nYear << endl; cout << "月" << nMonth <<endl; cout << "日" << nDay << endl; // 获取星期几 int nDayOfWeek = myDate.day_of_week(); cout << "星期" << nDayOfWeek <<endl; // 获取年内第几天 int nDayOfYear = myDate.day_of_year(); cout << "第" << nDayOfYear << "天" << endl; // 获取月末日期 date endOfMonth = myDate.end_of_month(); cout << "月末日期" << to_iso_string(endOfMonth) << endl; string strEndOfMonth = to_iso_string(endOfMonth); cout << strEndOfMonth << endl; // 支持加减运算 myDate += days(10); string strDate = to_iso_string(myDate); cout << "增加10天后的日期" << strDate << endl; int wait; cin >> wait; return 0; }
转载于:https://www.cnblogs.com/ganquanfu2008/p/3140994.html