Javatime-localdatetime-getmonthvalue

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

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

説明

  • java.time.LocalDateTime.getMonthValue()*メソッドは、1〜12の月のフィールドを取得します。

宣言

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

public int getMonthValue()

戻り値

1〜12の月。

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

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.getMonthValue());
   }
}

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

2