boost之date/time学习

来源:互联网 发布:阿里云资源短信包 编辑:程序博客网 时间:2024/04/27 16:31
#include<boost/timer.hpp>#include<iostream>#include <fstream>#include<vector>#include<string>#include <boost/progress.hpp>//date headerfile#include <boost/date_time/gregorian/gregorian.hpp>//time headerfile#include <boost/date_time/posix_time/posix_time.hpp>using namespace std;using namespace boost;using namespace boost::gregorian;using namespace boost::date_time;using namespace boost::posix_time;int main(){    //timer    timer t;    cout<<t.elapsed_max()<< endl;    cout<<t.elapsed_min()<<endl;    cout<<t.elapsed()<<endl;    //progress_timer    progress_timer pt;    cout<<pt.elapsed()<<endl;    //progress_display    vector<string> v(100);    ofstream fs("a.txt");    progress_display pd(v.size());    vector<string>::iterator pos;    for(pos=v.begin(); pos!=v.end();pos++)    {        fs<<*pos<<endl;        ++pd;    }    //date测试    date d1;    date d2(2011,1,1);    assert(d2.year()=2011);    assert(d2.month()=1);    assert(d2.day()=1);    date::ymd_type ymd = d2.year_month_day();    assert(ymd.year = 2011);    assert(ymd.month =1);    assert(ymd.day=1);    cout <<"day of week"<< d2.day_of_week() << endl;    cout <<"day of year" << d2.day_of_year()<<endl;    cout <<"end of month" << d2.end_of_month()<<endl;        date d3(2000,Jan,1);    date d4(d2);    assert(d1==date(not_a_date_time));    assert(d2 == d4);    assert(d3 < d4);    date d11 = from_string("2011/1/1");    date d22 = from_string("2011-1-1");    date d33 = from_undelimited_string("201111");    cout<<day_clock::local_day()<<endl;    cout<<day_clock::universal_day()<<endl;    cout<<second_clock::local_time()<<endl;    cout << microsec_clock ::local_time()<<endl;    //day的输出    cout << to_simple_string(d2);    cout << to_iso_string(d2);    cout << to_iso_extended_string(d2);    //day 到 C语言中tm的转换    tm t = to_tm(d2);    assert(t.tm_hour==0 && t.tm_min ==0);    date d2_copy = date_from_tm(t);    assert(d2==d2_copy)           return 0;}

原创粉丝点击