English English

Formatting LocalDate object as a string

LocalDate is a class with many features which can be used to create date and time in Java. It was introduced in Java 8. The class SimpleDateFormat cannot be used with LocalDate.

LocalDate object can be formatted with the class DateTimeFormatter. First create a LocalDate object with the current date.

LocalDate localDateObject = LocalDate.now();

Then create a DateTimeFormatter object to format the date as you wish.

DateTimeFormatter dtformat = DateTimeFormatter.ofPattern("dd.MM.yyyy");

"MM" stands for month. But "mm" stands for minute.


The DateTimeFormatter object can be called through this method directly.

String dateString = localDateObject.format(dtformat);

More information about the class "DateTimeFormatter":



We use cookies on our website. They are essential for the operation of the site