gpt4 book ai didi

java - 年月日的 Joda 期间

转载 作者:行者123 更新时间:2023-11-29 05:32:11 31 4
gpt4 key购买 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

请提供解决方案

最佳答案

你可以尝试改变

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
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com