获取正确范围内的 DateTime 倒数 - Joda Time

发布于 2024-12-16 13:29:15 字数 577 浏览 5 评论 0原文

我想得到日期时间的计数,该计数与乔达时间在正确的范围内。 我现在有这个版本,它只适合检查特定的一天:

public int getIntFatalitiesAtDay(DateTime AtDay) {

    int resultCount = 0;

    for( Fatality f : fatalities) {
        if(Days.daysBetween(f.date, AtDay).getDays() == 0) {
                    resultCount++;
        }
    }
    return resultCount;
}

当我每天循环抛出时,这很有用。但是现在我按月计算:

for (DateTime iDate = fa.firstDate; iDate.isBefore(fa.lastDate); iDate = iDate.plusMonths(1)) { ... }

现在我想了解该月的死亡人数。 有人可以帮忙吗?

(也是从那一年开始,虽然我也希望看到一个不考虑年份的选项,但这不太重要。)

I want to get the count back of DateTime that where within the correct range with Joda Time.
I have this version at the moment which is only good to check for a specific day:

public int getIntFatalitiesAtDay(DateTime AtDay) {

    int resultCount = 0;

    for( Fatality f : fatalities) {
        if(Days.daysBetween(f.date, AtDay).getDays() == 0) {
                    resultCount++;
        }
    }
    return resultCount;
}

This was usefull when i looped threw every day. However now i go by months with:

for (DateTime iDate = fa.firstDate; iDate.isBefore(fa.lastDate); iDate = iDate.plusMonths(1)) { ... }

And now i would like to get the count of fatalities that month.
Could someone help?

(Also from that year, althought i would like to see a option aswell where it doesn't look at the year but that's less important.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不醒的梦 2024-12-23 13:29:15

Java 的 java.util.Date 类具有用于确定一个日期是在另一个日期之前还是之后的方法。如果将 DateTime 对象转换为 Date 对象,您可以执行以下操作:

    if (f.date.after(beginngingDate) && f.date.before(endingDate)).

Java's java.util.Date class has methods for determining if one date is before or after another. If you convert the DateTime objects to Date objects, you can do:

    if (f.date.after(beginngingDate) && f.date.before(endingDate)).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文