boost ptime 与 time_t等的转换

来源:互联网 发布:网络致富平台 编辑:程序博客网 时间:2024/06/05 20:57
#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;}

原创粉丝点击