// Java program to get current
// system date and time
import java.text.SimpleDateFormat;
import java.util.*;
public class ConvDateString2DatePrg {
public static void main(String args[]) {
try {
//define date format to take input
SimpleDateFormat dateF = new SimpleDateFormat("dd/MM/yyyy");
Scanner sc = new Scanner(System.in); //string object
String dtString = "";
System.out.print("Enter date in dd/MM/yyyy format:");
dtString = sc.nextLine();
//convert input date string into Date
Date dt = dateF.parse(dtString);
System.out.print("Entered Date is: " + dt.toString());
} catch (Exception e) {
System.out.println("Exception is: " + e.toString());
}
}
}
Output
Enter date in dd/MM/yyyy format:21/09/2008
Entered Date is: Sun Sep 21 00:00:00 IST 2008
Consider the program:
Output