JODA期间没有返回正确的值?

时间:2012-11-07 14:54:09

标签: java jodatime

从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天?

1 个答案:

答案 0 :(得分:1)

尝试使用PeriodFormatter

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

输出:

4 weeks, 2 days, 23 hours, 59 minutes and 59 seconds