package nilpointer.net;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Demo {
public static void main(String[] args) {
LocalDate date = LocalDate.now();
System.out.println("Default format of LocalDate: " + date);
System.out.println(date.format(DateTimeFormatter.ofPattern("d::MMM::uuuu")));
System.out.println(date.format(DateTimeFormatter.BASIC_ISO_DATE));
LocalDateTime dateTime = LocalDateTime.now();
System.out.println("Default format of LocalDateTime: " + dateTime);
System.out.println(dateTime.format(DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss")));
System.out.println(dateTime.format(DateTimeFormatter.BASIC_ISO_DATE));
Instant timestamp = Instant.now();
System.out.println("Default format of Instant: " + timestamp);
LocalDateTime dt = LocalDateTime.parse("27::Apr::2014 21::39::48",
DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss"));
System.out.println("Default format after parsing: " + dt);
}
}
Default format of LocalDate: 2017-11-29
29::Nov::2017
20171129
Default format of LocalDateTime: 2017-11-29T15:44:45.440
29::Nov::2017 15::44::45
20171129
Default format of Instant: 2017-11-29T08:44:45.441Z
Default format after parsing: 2014-04-27T21:39:48