Format LocalDate as "yyyy MMM d"

Description

The following code shows how to format LocalDate as "yyyy MMM d".

Example


import java.time.LocalDate;
import java.time.Month;
import java.time.Year;
import java.time.format.DateTimeFormatter;
//from ww w  .  j ava2 s .  c o m
public class Main {
  public static void main(String[] args) {
    Month month = Month.valueOf("May".toUpperCase());
    LocalDate date = Year.now().atMonth(month).atDay(12);

    DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy MMM d");
    String out = date.format(format);
    System.out.printf("Given the date:  %s%n", out);
  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    Example »




Convert
Date
Timezone