C++boost 类库使用DateTime

// 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值