
package org.code2care.java.examples;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class LocalDateFormattingExample {
public static void main(String[] args) {
String dateFormat = "dd/MM/yyyy";
LocalDate localDateNow = LocalDate.now(); //get the date
System.out.println("LocalDate: " + localDateNow);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
String formattedDate = localDateNow.format(formatter);
System.out.println("Formatted LocalDate: " + formattedDate);
}
}
Output:
You can choose from the date formats based on the how it is represented in a specific country or region.
| Country | Date Format | Example |
|---|---|---|
| United States | MM/dd/yyyy | 09/28/2022 |
| United Kingdom | dd/MM/yyyy | 28/09/2022 |
| Canada | yyyy-MM-dd | 2022-09-28 |
| Australia | dd/MM/yyyy | 28/09/2022 |
| Japan | yyyy年MM月dd日 | 2022年09月28日 |
| Germany | dd.MM.yyyy | 28.09.2022 |
| France | dd/MM/yyyy | 28/09/2022 |
| India | dd/MM/yyyy | 28/09/2022 |
| China | yyyy年MM月dd日 | 2022年09月28日 |
| Brazil | dd/MM/yyyy | 28/09/2022 |
| Region | Date Format | Example |
|---|---|---|
| North America | MM/dd/yyyy | 04/22/2023 |
| Europe | dd/MM/yyyy | 22/04/2023 |
| China, Japan, Korea | yyyy/MM/dd | 2023/04/22 |
| Middle East | dd/MM/yyyy | 22/04/2023 |
| India, Bangladesh, Nepal | dd/MM/yyyy | 22/04/2023 |
| Southeast Asia | dd/MM/yyyy or yyyy-MM-dd | 22/04/2023 or 2023-04-22 |
| Australia, New Zealand | dd/MM/yyyy | 22/04/2023 |
| Latin America | dd/MM/yyyy or MM/dd/yyyy | 22/04/2023 or 04/22/2023 |
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!