boost::date boost::ptime

获取当前时间

boost::posix_time::ptime currentTime = boost::posix_time::second_clock::local_time();
boost::gregorian::date currentDate = boost::posix_time::second_clock::local_time().date();
boost::posix_time::time_duration newTimeDuration = boost::posix_time::second_clock::local_time().time_of_day();

日期时间段

boost::gregorian::date currentDate = boost::posix_time::second_clock::local_time().date();
boost::gregorian::date_duration newDateDuration = currentDate - boost::gregorian::date( 2000 , 01 , 01 );

时间段

boost::posix_time::ptime previousTime( previewDate , previousTimeDuration );
boost::posix_time::ptime currentTime = boost::posix_time::second_clock::local_time();
boost::posix_time::time_duration timeElapse = currentTime -  previousTime;

boost::posix_time::time_duration timeDuration_1 = boost::posix_time::hours( 3 );
boost::posix_time::time_duration timeDuration_2 = boost::posix_time::minutes(3);
boost::posix_time::time_duration timeDuration_3 = boost::posix_time::seconds(3);
boost::posix_time::time_duration timeDuration_4 = boost::posix_time::milliseconds(3);
boost::posix_time::time_duration timeDuration_5 = boost::posix_time::microseconds(3);

//#define BOOST_DATE_TIME_HAS_NANOSECONDS 1
//boost::posix_time::time_duration timeDuration_6 = boost::posix_time::nanoseconds(3);

boost::this_thread::sleep( timeDuration_1 );

时间字符串

string timeString = boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time());
//timeString = "20170120T121959"

boost::posix_time::time_duration timeDuration = boost::posix_time::duration_from_string("20:43:51");

boost::posix_time::ptime ptime_1 = boost::posix_time::time_from_string("2017-12-09 23:22:09");
boost::posix_time::ptime ptime_2 = boost::posix_time::from_iso_string("20171209T232308");
boost::posix_time::time_duration timeDuration = ptime_2 - ptime_1;
INT32 curHours = timeDuration.hours();           //0
INT32 curMinutes = timeDuration.minutes();       //0
INT32 curSeconds = timeDuration.seconds();       //59
INT64 mmmm = timeDuration.total_milliseconds();  //59000


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值