Java joda time PeriodFormatter不打印年份

Java joda time PeriodFormatter不打印年份,java,jodatime,Java,Jodatime,我有一个格式化程序,如下所示: private static PeriodFormatter formatter = new PeriodFormatterBuilder() .printZeroNever() .appendYears().appendSuffix(" years ") .appendMonths().appendSuffix(" months ") .appendWeeks().

我有一个格式化程序,如下所示:

 private static PeriodFormatter formatter = new PeriodFormatterBuilder()
            .printZeroNever()
            .appendYears().appendSuffix(" years ")
            .appendMonths().appendSuffix(" months ")
            .appendWeeks().appendSuffix(" weeks ")
            .appendDays().appendSuffix(" days ")
            .appendHours().appendSuffix(" hours ")
            .appendMinutes().appendSuffix(" minutes ")
            .appendSeconds().appendSuffix(" seconds")
            .toFormatter();
        DateTime dt = DateTime.parse("2010-06-30T01:20");
        Duration duration = new Duration(dt.toInstant().getMillis(), System.currentTimeMillis());

        Period period = duration.toPeriod().normalizedStandard(PeriodType.yearMonthDayTime());
        formatter.print(period);
并按如下方式使用:

 private static PeriodFormatter formatter = new PeriodFormatterBuilder()
            .printZeroNever()
            .appendYears().appendSuffix(" years ")
            .appendMonths().appendSuffix(" months ")
            .appendWeeks().appendSuffix(" weeks ")
            .appendDays().appendSuffix(" days ")
            .appendHours().appendSuffix(" hours ")
            .appendMinutes().appendSuffix(" minutes ")
            .appendSeconds().appendSuffix(" seconds")
            .toFormatter();
        DateTime dt = DateTime.parse("2010-06-30T01:20");
        Duration duration = new Duration(dt.toInstant().getMillis(), System.currentTimeMillis());

        Period period = duration.toPeriod().normalizedStandard(PeriodType.yearMonthDayTime());
        formatter.print(period);
输出为:

2274 days 13 hours 59 minutes 39 seconds

那么年份在哪里呢?

在我看来,这里的根本问题是你从
持续时间开始使用
。。。考虑年的数量有点麻烦,因为一年是365或366天(甚至这取决于日历系统)。这就是为什么政府明确表示:

将仅使用句点类型中的精确字段。因此,将仅使用周期上的小时、分钟、秒和毫秒字段。不会填充年、月、周和日字段

然后您拨打的电话包括:

“天”字段和“天”字段将根据需要进行规范化,但这不会溢出到“月”字段中。因此,1年15个月的期限将正常化为2年3个月。但1个月40天的期限将保留为1个月40天

不要从
持续时间
创建时段,而是直接从
日期时间
和“现在”创建时段,例如


这里的根本问题是你使用
Duration
开始,依我看,
Duration
只是毫秒数。。。考虑年的数量有点麻烦,因为一年是365或366天(甚至这取决于日历系统)。这就是为什么政府明确表示:

将仅使用句点类型中的精确字段。因此,将仅使用周期上的小时、分钟、秒和毫秒字段。不会填充年、月、周和日字段

然后您拨打的电话包括:

“天”字段和“天”字段将根据需要进行规范化,但这不会溢出到“月”字段中。因此,1年15个月的期限将正常化为2年3个月。但1个月40天的期限将保留为1个月40天

不要从
持续时间
创建时段,而是直接从
日期时间
和“现在”创建时段,例如