现在的位置: 首页 > 综合 > 正文

boost ptime 与 time_t等的转换

2013年08月25日 ⁄ 综合 ⁄ 共 520字 ⁄ 字号 评论关闭

 

#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
#include <stdint.h>
int main()
{
 using namespace boost::posix_time;
 using namespace boost::gregorian;

 ptime ptNow( second_clock::local_time() );
 std::cout << to_simple_string( ptNow ) << std::endl;

 // 转换成time_t
 tm tm1 = to_tm( ptNow );
 time_t tt = mktime( &tm1 );

 

 tm* tm2 = localtime( &tt );

 ptime ptt = from_time_t( tt );
 ptime pttm = ptime_from_tm( *tm2 );
 std::cout << to_simple_string( ptt ) << "/n" << to_simple_string( pttm ) << std::endl;
 return 0;
}

抱歉!评论已关闭.