BOOST 日期时间库 之 date 1/3
来源:互联网 发布:医疗器械软件分类 编辑:程序博客网 时间:2024/06/06 11:14
1.摘要:
基于格里高利历,支持1400-01-01到9999-12-31之间的日期计算.
使用一个32位的整数作为内部存储,以天为单位表示时间点概念.
2.包含头文件
#include <boost/date_time/gregorian/gregorian.hpp>
using namespace boost::gregorian;
3.构造
boost::gregorian::date d1( 2010, 1, 1 );
boost::gregorian::date d2( 2000, boost::gregorian::Jan, 1 );
boost::gregorian::date d3( d2 );
boost::gregorian::date d4; //空的构造会创建一个 not_a_date_time的无效日期;
4、比较操作
assert( d2 == d3 );
assert( d1 > d2 );
assert( d4 == boost::gregorian::date( boost::gregorian::not_a_date_time) );
5、使用字符串赋值
//from_string->使用分隔符(斜杠或连字符)分割年月日格式的字符串
boost::gregorian::date d51 = boost::gregorian::from_string( "1988-12-31" );
boost::gregorian::date d52( boost::gregorian::from_string("2008/1/1") );
//from_undelimited_string->使用无分隔符的纯字符串格式
boost::gregorian::date d53 = boost::gregorian::from_undelimited_string( "20110508" );
6;、时钟day_clock
boost::gregorian::day_clock::local_day(); //获得本地日期(date类型),依赖于系统的时区设置
boost::gregorian::day_clock::universal_day(); //UTC日期(date类型)
7、日期转为字符串
boost::gregorian::date date7( 2008, 11, 20 );
//to_simple_string->转为YYYY-mmm-DD格式,其中mmm为三个字符的英文月份名
//输出结果:2008-Nov-20
std::cout << boost::gregorian::to_simple_string( date7 ) << std::endl;
//to_iso_string->转为YYYYMMDD格式
//输出结果:20081120
std::cout << boost::gregorian::to_iso_string( date7 ) << std::endl;
//to_iso_extended_string->转为YYYY-MM-DD格式
//输出结果:2008-11-20
std::cout << boost::gregorian::to_iso_extended_string( date7 ) << std::endl;
基于格里高利历,支持1400-01-01到9999-12-31之间的日期计算.
使用一个32位的整数作为内部存储,以天为单位表示时间点概念.
2.包含头文件
#include <boost/date_time/gregorian/gregorian.hpp>
using namespace boost::gregorian;
3.构造
boost::gregorian::date d1( 2010, 1, 1 );
boost::gregorian::date d2( 2000, boost::gregorian::Jan, 1 );
boost::gregorian::date d3( d2 );
boost::gregorian::date d4; //空的构造会创建一个 not_a_date_time的无效日期;
4、比较操作
assert( d2 == d3 );
assert( d1 > d2 );
assert( d4 == boost::gregorian::date( boost::gregorian::not_a_date_time) );
5、使用字符串赋值
//from_string->使用分隔符(斜杠或连字符)分割年月日格式的字符串
boost::gregorian::date d51 = boost::gregorian::from_string( "1988-12-31" );
boost::gregorian::date d52( boost::gregorian::from_string("2008/1/1") );
//from_undelimited_string->使用无分隔符的纯字符串格式
boost::gregorian::date d53 = boost::gregorian::from_undelimited_string( "20110508" );
6;、时钟day_clock
boost::gregorian::day_clock::local_day(); //获得本地日期(date类型),依赖于系统的时区设置
boost::gregorian::day_clock::universal_day(); //UTC日期(date类型)
7、日期转为字符串
boost::gregorian::date date7( 2008, 11, 20 );
//to_simple_string->转为YYYY-mmm-DD格式,其中mmm为三个字符的英文月份名
//输出结果:2008-Nov-20
std::cout << boost::gregorian::to_simple_string( date7 ) << std::endl;
//to_iso_string->转为YYYYMMDD格式
//输出结果:20081120
std::cout << boost::gregorian::to_iso_string( date7 ) << std::endl;
//to_iso_extended_string->转为YYYY-MM-DD格式
//输出结果:2008-11-20
std::cout << boost::gregorian::to_iso_extended_string( date7 ) << std::endl;
阅读全文
0 0
- BOOST 日期时间库 之 date 1/3
- BOOST 日期时间库 之 时间点 posix_time 3/3
- (一)boost库之日期、时间
- Boost之日期时间处理(date_time库)
- BOOST 日期时间库 之 日期长度与日期区间 2/3
- boost库之date
- boost完全开发指南第2章-处理时间3(日期date)
- Boost库时间日期学习
- Boost之时间与日期处理
- boost之路 十 日期与时间
- JavaScript之日期和时间(date对象)
- boost -日期与时间相关库
- boost的时间和日期处理1
- boost日期、时间操作
- boost 时间和日期
- boost 时间与日期
- boost datetime 时间日期
- Scala Date 时间 日期
- HDU6050-Funny Function
- scikit-learn学习笔记(三)Generalized Linear Models ( 广义线性模型 )
- 百度前端技术学院task13-task15的总结
- 914电路原理
- Hibernate——VO对象与PO对象的区别
- BOOST 日期时间库 之 date 1/3
- Java异常基础知识
- 链表插入排序
- [渗透&攻防] 四.详解MySQL数据库攻防及Fiddler神器分析数据包
- 欢迎使用CSDN-markdown编辑器
- G
- SQL学习笔记--1
- 洛谷P1141 01迷宫 解题报告
- struts2 dwr There is no Action mapped for action ... 原因及解决方案