package DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class StringToDate {
public static void main(String[] args) throws ParseException {
String dateString = "21/4/2017";
SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");
//this step throws checked exception if main() doesn't throws ParseException
Date date = sdf.parse(dateString);
System.out.println("Date:"+ " " + date);
}
}
OUTPUT
Date: Sat Jan 21 00:04:00 IST 2017
Month should be April instead of Jan in the output.
ReplyDelete