Here’s how to format a LocalDateTime object.
import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public final class LocalDateTimeFormatter { private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); public static void main(String[] args) { LocalDateTime currentDateTime = LocalDateTime.now(); String formattedDateTime = currentDateTime.format(FORMATTER); System.out.println(formattedDateTime); } }
If you have any questions, leave a comment or ask me on my social media.