Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

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

0 contributions
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

References

  1. LocalDate - JavaDoc
  2. DateTimeFormatter - JavaDoc
  3. FormatStyle - JavaDoc
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more