boost::posix_time::ptime类型的时间取整
发布时间:2024年01月19日
时间取整(向前,向后)
#include <boost/date_time/posix_time/posix_time.hpp>
typedef boost::posix_time::ptime BoostTM;
BoostTM roundUpToNextHour(const BoostTM& time)
{
if (time.time_of_day().minutes() != 0 || time.time_of_day().seconds() != 0)
{
BoostTM rounded_up;
rounded_up = time + boost::posix_time::hours(1);
rounded_up = boost::posix_time::ptime(rounded_up.date(), boost::posix_time::hours(rounded_up.time_of_day().hours()));
return rounded_up;
}
else
{
return time;
}
}
BoostTM roundDownToPrevHour(const BoostTM& time)
{
if (time.time_of_day().minutes() != 0 || time.time_of_day().seconds() != 0)
{
BoostTM rounded_down;
rounded_down = boost::posix_time::ptime(time.date(), boost::posix_time::hours(time.time_of_day().hours()));
return rounded_down;
}
else
{
return time;
}
}
文章来源:https://blog.csdn.net/mankeywang/article/details/135700904
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!