Boost 时间处理
1、 引入的库文件
要使用C++boost 中的时间处理函数需要引入库
target_link_libraries(saveParm boost_date_time)
2、 需要引用的头文件及命名空间为
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
using namespace boost::gregorian;
using namespace boost::posix_time;
#define BOOST_DATE_TIME_SOURCE
3、 获得当前时间
ptime now = second_clock::local_time();
根据 ptime 得到时间:
date currentDay=now.date();
4、 从字符串中生成日期
date tempDate=from_string(“2016/12/09”);
5、 从时间戳中生成时间
ptime tempTime=from_time_t(1479826676);
6、 得到当前的星期
int weekday=currentDay.day_of_week();
7、 得到当前的小时
int currentHour=now.time_of_day().hours();