
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 |
-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Java,
- Java equals method - Tutorial
- Unbound classpath container: JRE System Library [JavaSE-1.7]
- Spring Boot: @RequestBody not applicable to method
- Java 8: Steam map with Code Examples
- Java Program: Random Number Generator
- Java java.time.Clock class code examples [Java Date Time API]
- Fix: type argument is not within bounds of type-variable T
- [Fix] java.net.MalformedURLException: unknown protocol
- Java 7 addSuppression() and getSuppression() Exception Handling
- Convert Java Array to ArrayList Code Example
- How to Word-Warp Console logs in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Remove Trailing zeros BigDecimal Java
- CRUD operations in Spring Boot + JDBC
- [Java Threads] Should we extend Thread Class or implement Runnable interface
- Json Serialization and Deserialization using Java Jackson
- Create simple struts2 project using maven commands
- How to install Java OpenJDK 11 on Alpine Linux
- Unsupported major.minor version 52.0 in java
- Error: Can not find the tag library descriptor for
- Java: Convert String to Binary
- How to run Java Unit Test cases with Apache Maven?
- Java: Testing Private Methods in JUnit using reflection API Example
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting
- Java Join Strings with Comma Separator
More Posts:
- How to deep copy a dictionary in Python - Python
- Ubuntu: How to Unzip a File using Terminal - Ubuntu
- Notepad++ delete lines above or below - NotepadPlusPlus
- Copy entire directory using Terminal Command [Linux, Mac, Bash] - Linux
- Compare Current and Previous Versions of Same File (Local History) in Eclipse - Eclipse
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu - Linux
- How to set an emoji as Zsh terminal prompt in macOS - MacOS
- [Solved] SharePoint Access Denied error editing Document Name - SharePoint