cuốn sách gpt4 ai đã làm

java - 年月日的 Joda 期间

In lại Tác giả: Walker 123 更新时间:2023-11-29 05:32:11 31 4
mua khóa gpt4 Nike

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

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

请提供解决方案

câu trả lời hay nhất

你可以尝试改变

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 - 年月日的 Joda 期间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20727066/

31 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress