简体   繁体   English

Joda-Time持续时间,以精确的十进制天为单位

[英]Joda-Time duration in exact decimal days

I'm trying to use Joda-Time's duration class to calculate the exact days different between two days. 我正在尝试使用Joda-Time的duration类来计算两天之间的确切天数。 Meaning I would like the result to be something like 25.48 days rather than just 25 days. 这意味着我希望结果是25.48天,而不是25天。 Right now I have: 现在我有:

private static final double MILLISECONDS_IN_DAY = 86400000;

DateTime today = new DateTime();
Duration dur = new Duration(foo.getExpirationDate(), today);
double diff_days = dur.getMillis()/MILLISECONDS_IN_DAY;

But I'm wondering if there's a way to combine the 1st and last line into one that just gives me a double. 但我想知道是否有一种方法可以将第一行和最后一行合并为一个,使我加倍。

You could eliminate the first line by using Joda-Time's constant instead of declaring your own. 您可以通过使用Joda-Time的常量来消除第一行,而不用声明自己的常量。

org.joda.time.DateTimeConstants.MILLIS_PER_DAY

Don't forget that if you're trying to calculate another date, there may be a better way to do this. 别忘了,如果您要计算另一个日期,可能会有更好的方法。 The irregularities in calendars such as leap years are well accounted for within Joda-Time. 在Joda-Time内可以很好地解决日历中的不规则性,例如leap年。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM