import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.Month; /** * Created by john on 2016/1/16. */ public class Java8LocalDateExample { public static void main(String[] args) { // Get the current date and time LocalDateTime currentTime = LocalDateTime.now(); System.out.println("Current DateTime: " + currentTime); LocalDate date1 = currentTime.toLocalDate(); System.out.println("Local Date: " + date1); Month month = currentTime.getMonth(); int day = currentTime.getDayOfMonth(); int second = currentTime.getSecond(); System.out.println("Month: "+month+" ,day: "+day+",second: "+second); LocalDateTime date2 = currentTime.withDayOfMonth(10).withYear(2012); System.out.println("Date2: "+date2); //12 December 2014 LocalDate date3 = LocalDate.of(2014,Month.DECEMBER,12); System.out.println("Date3: "+date3); //22 hour 15 minutes LocalTime date4 = LocalTime.of(22,15); System.out.println("Date4: "+date4); //parse a string LocalTime date5 = LocalTime.parse("20:15:30"); System.out.println("Date4: "+date5); } }