Javatime-localdate-of1

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

java.time.LocalDate.of()メソッドの例

説明

  • java.time.LocalDate.of(int year、Month month、int dayOfMonth)*メソッドは、年、月、日からLocalDateのインスタンスを取得します。

宣言

以下は、* java.time.LocalDate.of(int year、Month month、int dayOfMonth)*メソッドの宣言です。

public static LocalDate of(int year, Month month, int dayOfMonth)

パラメーター

  • year -MIN_YEARからMAX_YEARまでを表す年
  • -表す月
  • dayOfMonth -表す月の日、1〜31

戻り値

ローカル日付、null以外。

次の例は、java.time.LocalDate.of(int year、Month month、int dayOfMonth)メソッドの使用方法を示しています。

package com.finddevguides;

import java.time.LocalDate;
import java.time.Month;

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

      LocalDate date = LocalDate.of(2017,Month.FEBRUARY,3);
      System.out.println(date);
   }
}

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

2017-02-03