Languages
[Edit]
EN

Java 8 - LocalDate with DateTimeFormatter.ofLocalizedDate FormatStyle - FULL, SHORT, MEDIUM, LONG

6 points
Created by:
daniell
460

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

References

  1. LocalDate - JavaDoc
  2. DateTimeFormatter - JavaDoc
  3. FormatStyle - JavaDoc
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join