Java ZonedDateTime getMonth()方法及示例

Java ZonedDateTime getMonth()方法及示例

ZonedDateTime 类的 getMonth() 方法用于从这个ZonedDateTime中使用Month枚举来获取年月字段。如果你需要访问原始的int值,那么该枚举提供了int值。

语法

public Month getMonth()

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

返回值: 该方法返回一个代表年月的枚举月。

下面的程序说明了getMonth()方法。

程序1 :

// Java program to demonstrate
// ZonedDateTime.getMonth() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a ZonedDateTime object
        ZonedDateTime zoneddatetime
            = ZonedDateTime.parse(
                "2018-12-06T19:21:12.123+05:30[Asia/Calcutta]");
  
        // get month field
        Month value = zoneddatetime.getMonth();
  
        // print result
        System.out.println("month:" + value);
    }
}

输出。

month:DECEMBER

程序2

// Java program to demonstrate
// ZonedDateTime.getMonth() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a ZonedDateTime object
        ZonedDateTime zoneddatetime
            = ZonedDateTime.parse(
                "2018-10-25T23:12:38.543+02:00[Europe/Paris]");
  
        // get month field
        Month value = zoneddatetime.getMonth();
  
        // print result
        System.out.println("month:" + value);
    }
}

输出。

month:OCTOBER

参考资料: https://docs.oracle.com/javase/10/docs/api/java/time/ZonedDateTime.html#getMonth()

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程