Javatime-localdatetime-getmonth

提供:Dev Guides
移動先:案内検索

java.time.LocalDateTime.getMonth()メソッドの例

説明

  • java.time.LocalDateTime.getMonth()*メソッドは、Month列挙型を使用して月のフィールドを取得します。

宣言

以下は、* java.time.LocalDateTime.getMonth()*メソッドの宣言です。

public Month getMonth()

戻り値

月ではなく、null。

次の例は、java.time.LocalDateTime.getMonth()メソッドの使用法を示しています。

package com.finddevguides;

import java.time.LocalDateTime;

public class LocalDateTimeDemo {
   public static void main(String[] args) {

      LocalDateTime date = LocalDateTime.parse("2017-02-03T12:30:30");
      System.out.println(date.getMonth());
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

FEBRUARY