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
Java Program to format date as Apr 19, 2019, 1:27 PM
To format and display datetime, you need to use DateTimeFormatter. The format style is MEDIUM and SHORT:
DateTimeFormatter formatter = DateTimeFormatter .ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT);
Display the formatted date:
formatter.format(LocalDateTime.now()
Example
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
public class Demo {
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter .ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT);
System.out.println("Formatted Date = "+formatter.format(LocalDateTime.now()));
}
}
Output
Formatted Date = Apr 19, 2019, 1:27 PM
Advertisements
