如何使用boost :: date_time的获得两个日期之间的天数 [英] How to get the number of days between two dates using boost::date_time

查看:927
本文介绍了如何使用boost :: date_time的获得两个日期之间的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何的API,可提升DATE_TIME ::拿到天两个日期之间的数字,也历具体?

Are there any APIs available in boost::date_time to get the number of days between two dates that is also calendar specific?

为例,2005年1月1日和2006年12月31日之间的天数将是七天日历730将是504五天的日历。

Example, Number of days between 2005/01/01 and 2006/12/31 would be 730 in a seven day calendar and would be 504 in a five day calendar.

推荐答案

烨:了posix_time救援

Yup: posix_time to the rescue

<大骨节病> 住在Coliru

#include <boost/date_time/gregorian/greg_date.hpp>
#include <iostream>

int main() {
    using boost::gregorian::date;

    date a { 2005, 1, 1 }, b { 2006, 12, 31 };

    std::cout << (b-a).days() << "\n";
}

打印

729 [1]

使用 ::了posix_time分组时间如果你想使用阳历日子+一天中的时间(HH:MM:ss.fffffff)。 LOCAL_TIME :: LOCAL_DATE_TIME 添加了这个时区的意识(约为日光节约正确例如)

Use posix_time::ptime if you want to use gregorian date + time of day (hh:mm:ss.fffffff). local_time::local_date_time adds timezone awareness for this (to be correct about daylight savings e.g.)

<分> 花絮 顺便说一下这个数字也是27平方,和9的多维数据集,因为这些特性的结果,一个完美的totient号,中心的八角形数和史密斯号码。它的不可以的连续四个质数之和

Trivia Incidentally this number is also the square of 27, and the cube of 9, and as a consequence of these properties, a perfect totient number, a centered octagonal number, and a Smith number. It is not the sum of four consecutive primes

这篇关于如何使用boost :: date_time的获得两个日期之间的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆