java.time.LocalDate.of() Method Example


Advertisements

Description

The java.time.LocalDate.of(int year, Month month, int dayOfMonth) method obtains an instance of LocalDate from a year, month and day.

Declaration

Following is the declaration for java.time.LocalDate.of(int year, Month month, int dayOfMonth) method.

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

Parameters

  • year − the year to represent, from MIN_YEAR to MAX_YEAR

  • month − the month-of-year to represent

  • dayOfMonth − the day-of-month to represent, from 1 to 31

Return Value

the local date, not null.

Example

The following example shows the usage of java.time.LocalDate.of(int year, Month month, int dayOfMonth) method.

package com.tutorialspoint;

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);  
   }
}

Let us compile and run the above program, this will produce the following result −

2017-02-03
Advertisements