C++ boost库的ptime的使用

#include<iostream>
#include "common.h"
#include<string>
#include <ctype.h>
#include<boost/date_time.hpp>
using namespace boost::posix_time;
using namespace boost::gregorian;
using namespace std;

int main(int argc)
{
// 构造
ptime myPTime1(date(2013,6,1), hours(12));
ptime myPTime2 = from_iso_string("20130601T120000");
ptime myPTime3 = second_clock::local_time();
cout << to_iso_string(myPTime3) << endl;
ptime myPTime4 = second_clock::universal_time();

// 序列化
string str = to_iso_string(myPTime1);
str = to_iso_extended_string(myPTime2);
str = to_iso_extended_string(myPTime3);
str = to_iso_extended_string(myPTime4);

// 获取日期
date curDate = myPTime1.date();

// 获取时间
time_duration curTD = myPTime1.time_of_day();
int wait;
cin >> wait;

return 0;
}

posted @ 2013-07-20 13:29  Predator  阅读(2826)  评论(0编辑  收藏  举报