Java Date parse String like "21/08/2020"

Description

Java Date parse String like "21/08/2020"

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
  public static void main(String args[]) {
    String strDate = "21/08/2020";
    try {//  w  w  w  .j av a2  s.c  o m

      SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
      Date date = sdf.parse(strDate);
      System.out.println("Date is: " + date);
    } catch (ParseException e) {
      System.out.println("Java String could not be converted to Date: " + e);
    }
  }
}



PreviousNext

Related