boost之date/time学习

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值