我正在使用以下代码来获取年,月,日的两个日期之间的差异
tenAppDTO.getTAP_PROPOSED_START_DATE()=2009-11-01
tenAppDTO.getTAP_PROPOSED_END_DATE()=2013-11-29
ReadableInstant r=new DateTime(tenAppDTO.getTAP_PROPOSED_START_DATE());
ReadableInstant r1=new DateTime(tenAppDTO.getTAP_PROPOSED_END_DATE());
Period period = new Period(r, r1);
period.normalizedStandard(PeriodType.yearMonthDay());
years = period.getYears();
month=period.getMonths();
day=period.getDays();
out.println("year is-:"+years+"month is -:"+ month+"days is -:"+ day);
通过使用上面的代码,我得到的结果是-:4个月是-:0天是-:0
但实际结果是年是-:4个月是-:0天是-:28
请提供解决方案
最佳答案
您可以尝试改变
Period period = new Period(r, r1);
与
Period period = new Period(r, r1, PeriodType.yearMonthDay());
您可以这样尝试:
tenAppDTO.getTAP_PROPOSED_START_DATE()=2009-11-01
tenAppDTO.getTAP_PROPOSED_END_DATE()=2013-11-29
ReadableInstant r=new DateTime(tenAppDTO.getTAP_PROPOSED_START_DATE());
ReadableInstant r1=new DateTime(tenAppDTO.getTAP_PROPOSED_END_DATE());
Period period = new Period(r, r1, PeriodType.yearMonthDay()); //Change here
period.normalizedStandard(PeriodType.yearMonthDay());
years = period.getYears();
month=period.getMonths();
day=period.getDays();
out.println("year is-:"+years+"month is -:"+ month+"days is -:"+ day);
关于java - 年月日中的乔达期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20727066/