- java.time 包类
- java.time - 主页
- java.time - 时钟
- java.time - 时段
- java.time - 时间点
- java.time - 日期
- java.time - 日期时间
- java.time - 时间
- java.time - 月日
- java.time - 偏移日期时间
- java.time - 偏移时间
- java.time - 时段
- java.time - 年份
- java.time - 年份月份
- java.time - 时区日期时间
- java.time - 时区 ID
- java.time - 时区偏移
- java.time 包枚举
- java.time - 月份
- java.time 有用的资源
- java.time - 讨论
java.time.Period.normalized() 方法示例
说明
java.time.Period.normalized() 方法返回一个经年限和月数标准化后的本时段副本。
声明
以下是 java.time.Period.normalized() 方法的声明。
public Period normalized()
返回值
基于本时段,多余的月数已标准化为年限的一个时段,not null。
异常
ArithmeticException − 如果发生数值溢出。
示例
以下示例展示了 java.time.Period.normalized() 方法的用法。
package com.tutorialspoint;
import java.time.Period;
public class PeriodDemo {
public static void main(String[] args) {
Period period = Period.of(1,15,2);
System.out.println("Years: " + period.getYears()
+ ", Months: " + period.getMonths()
+", Days: " + period.getDays());
Period period1 = period.normalized();
System.out.println("Years: " + period1.getYears()
+ ", Months: " + period1.getMonths()
+", Days: " + period1.getDays());
}
}
让我们编译并运行上述程序,这将产生以下结果 −
Years: 1, Months: 15, Days: 2 Years: 2, Months: 3, Days: 2
广告