Java Time API – Formatting Dates


Use DateTimeFormatter to format and parse dates and times.

Source Code

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class DateFormatting {
    public static void main(String[] args) {
        LocalDate date = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
        String textDate = date.format(formatter);
        System.out.println(textDate);
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments