EN
Java 8 - LocalDate with DateTimeFormatter.ofLocalizedDate FormatStyle - FULL, SHORT, MEDIUM, LONG
6 points
In this post we cover usage of LocalDate.now() with DateTimeFormatter + FormatStyle.
xxxxxxxxxx
1
import java.time.LocalDate;
2
import java.time.format.DateTimeFormatter;
3
import java.time.format.FormatStyle;
4
5
public class Example1 {
6
7
public static void main(String[] args) {
8
9
LocalDate localDate = LocalDate.now();
10
11
System.out.println("# Example 1 - FULL ");
12
System.out.println(localDate.format(DateTimeFormatter
13
.ofLocalizedDate(FormatStyle.FULL)));
14
15
System.out.println("# Example 2 - LONG ");
16
System.out.println(localDate.format(DateTimeFormatter
17
.ofLocalizedDate(FormatStyle.LONG)));
18
19
System.out.println("# Example 3- MEDIUM ");
20
System.out.println(localDate.format(DateTimeFormatter
21
.ofLocalizedDate(FormatStyle.MEDIUM)));
22
23
System.out.println("# Example 4 - SHORT ");
24
System.out.println(localDate.format(DateTimeFormatter
25
.ofLocalizedDate(FormatStyle.SHORT)));
26
}
27
}
Output:
xxxxxxxxxx
1
# Example 1 - FULL
2
Sunday, October 13, 2019
3
# Example 2 - LONG
4
October 13, 2019
5
# Example 3- MEDIUM
6
Oct 13, 2019
7
# Example 4 - SHORT
8
10/13/19