Languages
[Edit]
EN

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

6 points
Created by:
Kate_C
2845

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

Checkout latest findings & news:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Rockstar community members
Thank you for great work 👍