- 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.of() 方法示例
描述
java.time.Period.of(int years, int months, int days) 方法获取表示指定单位中量的周期。
声明
以下是 java.time.Period.of(int years, int months, int days) 的声明。
public static Period of(int years, int months, int days)
参数
years - 年份,可以为负数。
months - 月份,可以为负数。
days - 天数,可以为负数。
返回值
周期,不为 null。
示例
以下示例演示了 java.time.Period.of(int years, int months, int days) 方法的使用。
package com.tutorialspoint;
import java.time.Period;
public class PeriodDemo {
public static void main(String[] args) {
Period period = Period.of(1,5,2);
System.out.println("Years: " + period.getYears()
+ ", Months: " + period.getMonths()
+", Days: " + period.getDays());
}
}
让我们编译并运行以上程序,这将产生以下结果 -
Years: 1, Months: 5, Days: 2
广告