Java Date Time - LocalDate format(DateTimeFormatter formatter) example








LocalDate format(DateTimeFormatter formatter) formats this date using the specified formatter. This date will be passed to the formatter to produce a string.

Syntax

format has the following syntax.

public String format(DateTimeFormatter formatter)

Example

The following example shows how to use format.

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/*from w w w.j a  v  a 2  s .c o  m*/
public class Main {
  public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);

    String s = a.format(DateTimeFormatter.BASIC_ISO_DATE);
    
    System.out.println(s); 
  }
}

The code above generates the following result.