Home » Formatting a LocalDateTime object

Formatting a LocalDateTime object

gold and white analog watch

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.

Leave a Reply

Your email address will not be published. Required fields are marked *