java.time.Period.from()
方法从时间量获取Period的实例。
声明
以下是java.time.Period.from()
方法的声明。
public static Period from(TemporalAmount amount)
参数
amount
- 要转换的时间量,而不是null
。
返回值
等效的Period
,不为null
。
异常
DateTimeException
- 如果无法转换为Period
。ArithmeticException
- 如果发生数字溢出。
示例
以下示例显示了java.time.Period.from()
方法的用法。
package com.yiibai;
import java.time.Period;
public class PeriodDemo {
public static void main(String[] args) {
Period period = Period.from(Period.of(20, 10, 5));
System.out.println(period);
}
}
编译并运行上面的程序,这将产生以下结果 -
P20Y10M5D