Java Can';t使用Joda time将DateTime转换为ReadableInstant
我想找出两个日期之间的年数。我编写了一个简单的测试用例来验证这一点Java Can';t使用Joda time将DateTime转换为ReadableInstant,java,datetime,jodatime,Java,Datetime,Jodatime,我想找出两个日期之间的年数。我编写了一个简单的测试用例来验证这一点 @Test public void testGetYears() { DateTime oldDate = new DateTime(2014,1,1,0,0,0,0); DateTime newDate = new DateTime(2016,2,1,0,0,0,0); Days.daysBetween(oldDate, newDate).getDays(); //this line works
@Test
public void testGetYears() {
DateTime oldDate = new DateTime(2014,1,1,0,0,0,0);
DateTime newDate = new DateTime(2016,2,1,0,0,0,0);
Days.daysBetween(oldDate, newDate).getDays(); //this line works
Years.yearsBetween(oldDate, newDate).getYears(); //no suitable method found
assertEquals(2, Years.yearsBetween(oldDate, newDate).getYears());
}
错误:
Error:(146, 14) java: no suitable method found for yearsBetween(org.elasticsearch.common.joda.time.DateTime,org.elasticsearch.common.joda.time.DateTime)
method org.joda.time.Years.yearsBetween(org.joda.time.ReadableInstant,org.joda.time.ReadableInstant) is not applicable
(argument mismatch; org.elasticsearch.common.joda.time.DateTime cannot be converted to org.joda.time.ReadableInstant)
method org.joda.time.Years.yearsBetween(org.joda.time.ReadablePartial,org.joda.time.ReadablePartial) is not applicable
(argument mismatch; org.elasticsearch.common.joda.time.DateTime cannot be converted to org.joda.time.ReadablePartial)
我已经研究了yearsBetween定义,它需要与daysBetween函数中相同的参数。所以我想知道为什么它在两个月之间都不起作用
我在这里遗漏了什么吗?您可以使用:
DateTime oldDate = new DateTime(2014,1,1,0,0,0,0);
DateTime newDate = new DateTime(2016,2,1,0,0,0,0);
Period p = new Period(oldDate, newDate);
int years = p.getYears();
检索两个日期之间的年份。您可以使用:
DateTime oldDate = new DateTime(2014,1,1,0,0,0,0);
DateTime newDate = new DateTime(2016,2,1,0,0,0,0);
Period p = new Period(oldDate, newDate);
int years = p.getYears();
检索两个日期之间的年份。您尝试使用elasticsearch(
org.elasticsearch.common.joda.time.DateTime
)提供的DateTime
)和joda time本身的年类(org.joda.time.years
)
在任何地方使用joda时间类或elasticsearch提供的joda时间类;但不是两个都在同一时间 您尝试使用elasticsearch(org.elasticsearch.common.joda.time.DateTime
)提供的DateTime
)和joda time本身的Years
类(org.joda.time.Years
)
在任何地方使用joda时间类或elasticsearch提供的joda时间类;但不是两个都在同一时间 哦,我明白了。岁月不是乔达时代的弹性版本。哦,我明白了。年不是乔达时间的弹性版本的一部分。