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 = LocalDate.now(); System.out.println(String.format("Year : %s Month : %s day : %s", today.getYear(), today.getMonthValue(), today.getDayOfMonth())); LocalDateTime time = LocalDateTime.now(); System.out.println(String.format("Hour : %s Mins : %s Sec : %s", time.getHour(), time.getMinute(), time.getSecond())); } }
The code above generates the following result.