Java Data Type How to - Parse and format date in basic ISO date format


We would like to know how to parse and format date in basic ISO date format.


import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
  public static void main(String[] argv) {
    String dayAfterTommorrow = "20140116";
    LocalDate formatted = LocalDate.parse(dayAfterTommorrow, DateTimeFormatter.BASIC_ISO_DATE);
    System.out.printf("Date generated from String %s is %s %n", dayAfterTommorrow, formatted);
    System.out.println("Formatted today = " + DateTimeFormatter.BASIC_ISO_DATE.format(;
//from   w  w w .  j av a 2  s  .c o  m

The code above generates the following result.