Boost之时间与日期处理
2015-01-19 21:18
567 查看
类 | 特点 | 缺点 | 说明 |
timer | 计时基类 | 不适合大跨度时间 | 适用大部分的普通计时 |
progress_timer | 继承自timer 可以自动写入流中 | 只精确到0.01s | 如果需要更精确,可派生,退出局部域,自动调用elapsed() |
progress_display | 图形化显示进度 | 无法把进度显示输出与 程序显示输出分离 | 如果还有其他输出则会干扰进度显示。 折中的办法是重新显示 { pd.restart(size); pd+= pNum; } |
date | 日期结构,时间点,核心类 | —— | 支持日期运算 |
date_duration | 时间长度 | —— | 表示一段时间,可以把它看成一个int |
date_period | 标量,左开右闭,时间区间 | —— | 左闭右开,可以认为是一个有起点的date_duration。能做交集、并集 |
date_iterator | 迭代器,以某个单位增减 | —— | ady_iterator,week_iterator,month_iterator.....天、周、月、年四种迭代器,以某种增量移动。 |
time_duration | 时间段 同date_duration | —— | hours、minutes、seconds、millisec、boost::posix_time |
ptime | 时间点 date+time_duration | —— | 分date()和time_of_day()操作。 |
time_period | 时间区间 同date_period | —— | —— |
time_iterator | 迭代器,以某个单位增减 | —— | 可直接与ptime比较 |
date_facet | 流格式化日期 | —— | %Y年%m月%d日 |
time_facet | 流格式化时间 | —— | %Y年%m月%d日 %H点%M分%S%F秒 |
#include<boost/progress.hpp> #include<iostream> using namespace boost; using namespace std; int main() { progress_timer t; cout<<"max timespan:" <<t.elapsed_max()/3600<<"h"<<endl; cout<<"min_timespan:" <<t.elapsed_min()<<"s"<<endl; { progress_timer t1; } { progress_timer t2; for(int i=0;i<100;i++); } }
#include<boost/date_time/gregorian/gregorian.hpp> using namespace boost::gregorian; using namespace std; int main() { date d(2008,11,20); date d18years = d + years(18); cout << d18years <<" is " <<d18years.day_of_week()<<endl; int count=0; for( day_iterator d_iter(date(d18years.year(),11,1)) ; d_iter != d18years.end_of_month();++d_iter) { if(d_iter->day_of_week()==Sunday) { ++count; } } cout<< "total "<<count<<"Sunday."<<endl; count=0; for(month_iterator m_iter(date(d18years.year(),1,1)); m_iter<date(d18years.year()+1,1,1);++m_iter) { count+=m_iter->end_of_month().day(); } cout<< "total "<<count<<"days of year."<<endl; }
#include<boost/date_time/gregorian/gregorian.hpp> using namespace boost::gregorian; using namespace std; int main() { date d1(2000,1,1),d2(2008,8,8); cout<<d2-d1<<endl; assert(d1+(d2-d1)==d2); d1+=days(10); assert(d1.day()==11); d1+=months(2); assert(d1.month()==3&&d1.day()==11); d1-=weeks(1); assert(d1.day()==4); d2-=years(7); assert(d2.year()==d1.year()+1); date d3(2010,1,1); date d4=d3+days(pos_infin); assert(d4.is_pos_infinity()); d4=d3+days(not_a_date_time); assert(d4.is_not_a_date()); d4=date(neg_infin); days dd= d3-d4; assert(dd.is_special()&&!dd.is_negative()); }
#include<vector> #include<fstream> #include<boost/progress.hpp> using namespace boost; using namespace std; int main() { std::vector<std::string> v(100); std::ofstream fs("./test.txt"); progress_display pd(v.size()); for(vector<string>::iterator x=v.begin();x!=v.end();x++) { fs<<*x<<std::endl; ++pd; } }
#include<boost/date_time/gregorian/gregorian.hpp> using namespace boost::gregorian; int main() { //boost::gregorian::date d1=from_string("1999-12-31"); boost::gregorian::date d2=from_undelimited_string("20011118"); std::cout<<day_clock::local_day()<<std::endl; std::cout<<day_clock::universal_day()<<std::endl; date d(2015,1,20); //std::cout<<to_simple_string(d)<<std::endl; //std::cout<<to_iso_string(d)<<std::endl; //std::cout<<to_iso_extended_string(d)<<std::endl; std::cout<<d<<std::endl; }
相关文章推荐
- boost 时间与日期处理
- boost 时间与日期处理
- boost完全开发指南第2章-处理时间3(日期date)
- boost 时间与日期处理
- [Boost]boost的时间和日期处理-(2)时间的操作
- boost处理日期和时间的总结
- boost 时间与日期处理
- [Boost]boost的时间和日期处理-(2)时间的操作
- [Boost]boost的时间和日期处理-(1)日期的操作
- C++ boost 时间与日期处理详细介绍
- boost 时间与日期处理
- boost的时间和日期处理1
- [Boost]boost的时间和日期处理日期的操作和时间的操作
- Boost之日期时间处理(date_time库)
- boost完全开发指南第2章-处理时间4 (日期区间date_period)
- [Boost]boost的时间和日期处理-(3)输入输出格式
- [Boost]boost的时间和日期处理-(1)日期的操作
- boost 时间与日期处理测试
- ORACLE/JSP技术涉及日期、时间问题的处理
- jsp 中关于日期时间处理的几个问题