年月日中的乔达期 [英] Joda Period in year month day

查看:55
本文介绍了年月日中的乔达期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码获取年,月,日中2个日期之间的差异

i am using following code to get difference between 2 dates in year,month,day

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

by using above code i get the result year is-:4 month is -:0 days is -:0 but actual result is year is-:4 month is -:0 days is -: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);

这篇关于年月日中的乔达期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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