目录

static Year from(TemporalAmount amount)

描述 (Description)

java.time.Year.from(TemporalAmount amount)方法从时间量获取Year的实例。

声明 (Declaration)

以下是java.time.Year.from(TemporalAmount amount)方法的声明。

public static Year from(TemporalAmount amount)

参数 (Parameters)

amount - 要转换的时间量,而不是null。

返回值 (Return Value)

等效年份,不为空。

异常 (Exception)

  • DateTimeException - 如果无法转换为Year。

  • ArithmeticException - 如果发生数字溢出。

例子 (Example)

以下示例显示了java.time.Year.from(TemporalAmount amount)方法的用法。

package com.iowiki;
import java.time.Year;
public class YearDemo {
   public static void main(String[] args) {
      Year date = Year.from(Year.of(2017));
      System.out.println(date);
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

2017
↑回到顶部↑
WIKI教程 @2018