Java Data Type How to - Get current day, month and year in Java 8


We would like to know how to get current day, month and year in Java 8.


import java.time.LocalDate;
import java.time.LocalDateTime;
/*from   ww  w  . jav  a  2  s .co  m*/
public class Main {
  public static void main(String[] argv) {
    LocalDate today =;
    System.out.println(String.format("Year : %s Month : %s day : %s",
        today.getYear(), today.getMonthValue(), today.getDayOfMonth()));

    LocalDateTime time =;
    System.out.println(String.format("Hour : %s Mins : %s Sec : %s",
        time.getHour(), time.getMinute(), time.getSecond()));


The code above generates the following result.