Home  >  Forum  >  Core Java
Post New Query

How to format LocalDate in Java?

Asked on December 06, 2018
Java 8 LocalDate is giving date format as yyyy-MM-dd. How can I change it to dd-MM-yyyy?

Replied on December 06, 2018
Use LocalDate format() method and pass DateTimeFormatter. Find the code.

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

public class LocalDateDemo {
  public static void main(String[] args) {
LocalDate localDate = LocalDate.parse("2018-02-18");

String formattedDate = localDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy"));

formattedDate = localDate.format(DateTimeFormatter.ofPattern("MMM dd, yyyy"));


Feb 18, 2018 

Write Answer

©2022 concretepage.com | Privacy Policy | Contact Us