- 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 - 时区标识符
- java.time - 时区偏移量
- java.time 包枚举
- java.time - 月份
- 有用的 java.time 资源
- java.time - 讨论
java.time.Period.ofYears() 方法示例
描述
java.time.Period.ofYears(int years) 方法获取表示年数的时段。
声明
下面是 java.time.Period.ofYears(int years) 方法的声明。
public static Period ofYears(int years)
```java
参数
years − 年数,正数或负数。
返回值
年数时段,非空。
示例
package com.tutorialspoint;
import java.time.Period;
public class PeriodDemo {
public static void main(String[] args) {
Period period = Period.ofYears(2);
System.out.println(period.getYears());
}
}
实时演示
2
打印页面
广告