Java Data Type How to - Format LocalDateTime with d. MMMM yyyy in French as 1. avril 2014








Question

We would like to know how to format LocalDateTime with d. MMMM yyyy in French as 1. avril 2014.

Answer

/*ww  w .j  a  va  2s. com*/
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Main {
  public static void main(String[] args) {
    // 2014-04-01 10:45
    LocalDateTime dateTime = LocalDateTime.of(2014, Month.APRIL, 1, 10, 45);

    // french date formatting (1. avril 2014)
    String frenchDate = dateTime.format(DateTimeFormatter.ofPattern("d. MMMM yyyy", new Locale("fr")));
    
    System.out.println(frenchDate);
  }
}

The code above generates the following result.