Java year getValue()方法及示例

来源:这里教程网 时间:2026-02-17 21:17:57 作者:

Java year getValue()方法及示例

Java中Year类的getValue()方法是用来获取当前Year对象的积分值。

语法:

public int getValue()

参数 :该方法不接受任何参数。

返回值 :它返回一个整数,表示当前年份对象的值。

下面的程序说明了Java中年份的getValue()方法。

程序1 :

// Program to illustrate the getvalue() method  import java.util.*;import java.time.*;import java.time.format.DateTimeFormatter;  public class GfG {    public static void main(String[] args)    {        // Creates a Year object        Year firstYear = Year.of(1997);          // Print the value of the current year        // using getValue() method        System.out.println(firstYear.getValue());    }}

输出:

1997

程序2 :

// Program to illustrate the getvalue() method  import java.util.*;import java.time.*;import java.time.format.DateTimeFormatter;  public class GfG {    public static void main(String[] args)    {        // Creates a Year object        Year firstYear = Year.of(2018);          // Print the value of the current year        // using getValue() method        System.out.println(firstYear.getValue());    }}

输出:

2018

参考资料 : https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#getValue-

相关推荐