1

来自 JODA API 的返回是否有意义?

DateTime sd = new DateTime(1973,1,1,0,0,0);
DateTime ed = new DateTime(1973,1,31,23,59,59);
Period p = new Period(sd,ed);

StringBuilder buf = new StringBuilder();
buf.append(p.getYears()).append(" years ")
        .append(p.getMonths()).append(" months ")
        .append(p.getDays()).append(" days");
System.out.println(buf.toString());

返回 0 年 0 个月 2 天?

4

1 回答 1

1

尝试使用PeriodFormatter

System.out.println(PeriodFormat.getDefault().print(p));

输出:

4 weeks, 2 days, 23 hours, 59 minutes and 59 seconds
于 2012-11-07T15:04:29.107 回答