ptime转换问题

 1  #include  < boost / date_time / posix_time / posix_time.hpp >
 2  #include  < boost / date_time / gregorian / gregorian.hpp >
 3  #include  < iostream >
 4  #include  < stdint.h >
 5 
 6  int  main()
 7  {
 8       using   namespace  boost::posix_time;
 9       using   namespace  boost::gregorian;
10 
11      ptime ptNow( second_clock::local_time() );
12      std::cout  <<  to_simple_string( ptNow )  <<  std::endl;
13 
14      tm tm1  =  to_tm( ptNow );
15      time_t tt  =  mktime(  & tm1 );
16 
17      tm *  tm2  =  localtime(  & tt );
18 
19      ptime ptt  =  from_time_t( tt );
20      ptime pttm  =  ptime_from_tm( tm1 );
21      std::cout  <<  to_simple_string( ptt )  <<   " \n "   <<  to_simple_string( pttm )  <<  std::endl;
22 
23       return   0 ;
24  }

输出结果:
2009-Sep-10 15:24:10
2009-Sep-10 07:24:10
2009-Sep-10 15:24:10

第一个为ptime获得的当前时间的输出。
第三个为ptime转为tm,再tm转成ptime的输出
第二个为那个tm转成time_t,time_t再转回ptime的输出。

从结果看,第二个输出的时间很诡异上居然差了8个小时,难道是UTC时间?但boost doc那里没有这个说明,只是说用from_time_t可以将time_t转成ptime。程序中间将time_t用localtime转回tm作验证,结果是正确的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值