get() Methods

Description

getXXX() returns the specified element of the object.

Example

The following code shows how to get year, month, and day from a LocalDate object:


import java.time.LocalDate;
import java.time.Month;
//from  w w  w .j ava2s  .c  o  m
public class Main {
  public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, 6, 21);
    int year = localDate.getYear();
    System.out.println(year);
    Month month = localDate.getMonth();
    System.out.println(month);

    int day = localDate.getDayOfMonth();
    System.out.println(day);

  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    Tutorial »




Java Date Time Tutorial