How can I display Java date as '12/04/2019'


To format and display date like this i.e. Day/Month/Year, you need to set the pattern:

dd/MM/yyyy

At first, set a LocalDate:

LocalDate localDate = LocalDate.now();

Now format and display date as '12/04/2019':

localDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))

Example

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Demo {
   public static void main(String[] args) {
      LocalDate date = LocalDate.now();
      System.out.println("Date = "+date);
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
      System.out.println("Formatted Date = "+date.format(formatter));
   }
}

Output

Date = 2019-04-12
Formatted Date = 12/04/2019

Updated on: 30-Jul-2019

55 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements