EN
Java 8 - LocalDate with DateTimeFormatter.ofLocalizedDate FormatStyle - FULL, SHORT, MEDIUM, LONG
6
points
1. Overview
In this post we cover usage of LocalDate.now() with DateTimeFormatter + FormatStyle.
2. Usage example of LocalDate + DateTimeFormatter + FormatStyle
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
public class Example1 {
public static void main(String[] args) {
LocalDate localDate = LocalDate.now();
System.out.println("# Example 1 - FULL ");
System.out.println(localDate.format(DateTimeFormatter
.ofLocalizedDate(FormatStyle.FULL)));
System.out.println("# Example 2 - LONG ");
System.out.println(localDate.format(DateTimeFormatter
.ofLocalizedDate(FormatStyle.LONG)));
System.out.println("# Example 3- MEDIUM ");
System.out.println(localDate.format(DateTimeFormatter
.ofLocalizedDate(FormatStyle.MEDIUM)));
System.out.println("# Example 4 - SHORT ");
System.out.println(localDate.format(DateTimeFormatter
.ofLocalizedDate(FormatStyle.SHORT)));
}
}
Output:
# Example 1 - FULL
Sunday, October 13, 2019
# Example 2 - LONG
October 13, 2019
# Example 3- MEDIUM
Oct 13, 2019
# Example 4 - SHORT
10/13/19