LocalDate format(DateTimeFormatter formatter) example

Description

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 www . ja  v  a 2s .  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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset