Java ZonedDateTime getMonthValue()方法及示例

Java ZonedDateTime getMonthValue()方法及示例

ZonedDateTime 类的 getMonthValue() 方法是用来从这个ZonedDateTime中获取1到12之间的年月场。

语法

public int getMonthValue()

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

返回值: 该方法返回一个代表年月的整数,从1到12。

以下程序说明了getMonthValue()方法。

程序1 :

// Java program to demonstrate
// ZonedDateTime.getMonthValue() 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
        int value = zoneddatetime.getMonthValue();
  
        // print result
        System.out.println("month:" + value);
    }
}

输出。

month:12

程序2

// Java program to demonstrate
// ZonedDateTime.getMonthValue() 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
        int value = zoneddatetime.getMonthValue();
  
        // print result
        System.out.println("month:" + value);
    }
}

输出。

month:10

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程