1.date
// date_Exam.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#define BOOST_DATE_TIME_SOURCE
#include "libs/date_time/src/gregorian/greg_names.hpp"
#include "libs/date_time/src/gregorian/date_generators.cpp"
#include "libs/date_time/src/gregorian/greg_month.cpp"
#include "libs/date_time/src/gregorian/greg_weekday.cpp"
#include "libs/date_time/src/gregorian/gregorian_types.cpp"
#include "boost/date_time/gregorian/conversion.hpp"
#include "boost/date_time/gregorian/gregorian.hpp"
using namespace boost::gregorian;
int _tmain(int argc, _TCHAR* argv[])
{
date d1;
date d2(2012, 5, 4);
std::cout << d1.is_not_a_date() << std::endl;
std::cout << d1.is_infinity() << std::endl;
std::cout << d1.is_neg_infinity() << std::endl;
std::cout << d1.is_pos_infinity() << std::endl;
std::cout << d1.is_special() << std::endl;
std::cout << d2.year() << std::endl;
std::cout << d2.month() << std::endl;
std::cout << d2.day() << std::endl;
std::cout << to_simple_string(d2) << std::endl;
std::cout << to_iso_string(d2) << std::endl;
std::cout << to_iso_extended_string(d2) << std::endl;
tm t = to_tm(d2);
date d3 = date_from_tm(t);
//时间长度
date_duration dd(1);
date d4(2008, 1, 1);
d4 = d4 + dd;
std::cout << to_simple_string(d4) << std::endl;
years y1(10);
d4 = d4 + y1;
std::cout << to_simple_string(d4) << std::endl;
//日期区间
date_period dp1(d4, days(10));
return 0;
}
2.time_duration
// posix_time_Exam.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#define BOOST_DATE_TIME_SOURCE
#include "libs/date_time/src/gregorian/greg_names.hpp"
#include "libs/date_time/src/gregorian/date_generators.cpp"
#include "libs/date_time/src/gregorian/greg_month.cpp"
#include "libs/date_time/src/gregorian/greg_weekday.cpp"
#include "libs/date_time/src/gregorian/gregorian_types.cpp"
#include "boost/date_time/gregorian/conversion.hpp"
#include "boost/date_time/gregorian/gregorian.hpp"
#include "boost/date_time/posix_time/posix_time.hpp"
using namespace boost::posix_time;
int _tmain(int argc, _TCHAR* argv[])
{
// 时间长度
time_duration td(1, 10, 30, 1000);
hours h(1);
minutes m(10);
seconds s(30);
millisec ms(1);
time_duration td1 = h + m + s + ms;
time_duration td2 = duration_from_string("1:10:30:001");
std::cout << td.total_microseconds() << std::endl;
std::cout << td1.total_microseconds() << std::endl;
std::cout << td2.total_microseconds() << std::endl;
// 时间点
using namespace boost::gregorian;
ptime p(date(2010, 3, 5), hours(1));
std::cout << p << std::endl;
return 0;
}