java.time.LocalDate.of() 方法示例



說明

java.time.LocalDate.of(int year, int month, int dayOfMonth) 方法從一個年份、月份和日期獲取一個 LocalDate 例項物件。

宣告

以下是 java.time.LocalDate.of(int year, int month, int dayOfMonth) 方法的宣告。

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

引數

  • year − 年份,從 MIN_YEAR 到 MAX_YEAR

  • month − 月份,從 1(1 月)到 12(12 月)

  • dayOfMonth − 月中天,從 1 到 31

返回值

本地日期,非空。

示例

以下示例展示了 java.time.LocalDate.of(int year, int month, int dayOfMonth) 方法的用法。

package com.tutorialspoint;

import java.time.LocalDate;

public class LocalDateDemo {
   public static void main(String[] args) {
	  
      LocalDate date = LocalDate.of(2017,2,3);
      System.out.println(date);  
   }
}

讓我們編譯並執行上面的程式,它將會生成以下結果 −

2017-02-03
列印頁面