Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How can I display Java date as '12/04/2019'
To format and display date like this i.e. Day/Month/Year, you need to set the pattern:
dd/MM/yyyy
At first, set a LocalDate:
LocalDate localDate = LocalDate.now();
Now format and display date as '12/04/2019':
localDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))
Example
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Demo {
public static void main(String[] args) {
LocalDate date = LocalDate.now();
System.out.println("Date = "+date);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
System.out.println("Formatted Date = "+date.format(formatter));
}
}
Output
Date = 2019-04-12 Formatted Date = 12/04/2019
Advertisements
