Java month getLong()方法

Java month getLong()方法

getLong() 方法是Month ENUM的一个内置方法,用来从这个月的实例中获取指定的时间字段的值,作为一个长条。

语法:

public long getLong(TemporalField field)

参数 :该方法接受一个单一的参数字段,其长值将从这个月的实例中返回。

返回值 :该方法将指定字段的值作为一个长条返回。

下面的程序说明了上述方法。

程序1 :

import java.time.*;
import java.time.Month;
import java.time.temporal.ChronoField;
  
class monthEnum {
    public static void main(String[] args)
    {
        // Create a month instance
        Month month = Month.MARCH;
  
        // Get the value of field
        System.out.println(month.getLong(ChronoField.MONTH_OF_YEAR));
    }
}

输出。

3

程序2 :

import java.time.*;
import java.time.Month;
import java.time.temporal.ChronoField;
  
class monthEnum {
    public static void main(String[] args)
    {
        // Create a month instance
        Month month = Month.DECEMBER;
  
        // Get the value of field
        System.out.println(month.getLong(ChronoField.MONTH_OF_YEAR));
    }
}

输出。

12

参考资料 : https://docs.oracle.com/javase/8/docs/api/java/time/Month.html#getLong-java.time.temporal.TemporalField-

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程