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);