Formatting Dates with DateTimeFormatter in Java


Use DateTimeFormatter to format and parse date-time objects in a locale-sensitive manner.

Source Code

LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = now.format(formatter); // Custom format
System.out.println("Formatted DateTime: " + formattedDateTime);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments