Got one problem wherein i have to convert one date format to another date format and have to return java.sql.Date in a particular format.
I have input format as MM/dd/yyyy and output format should be dd-MM-yy ..but unable to get it
DateFormat orgFormat = new SimpleDateFormat("MM/dd/yyyy");
DateFormat targetFormat = new SimpleDateFormat("dd-MM-yy");
try {
java.util.Date inputDate = orgFormat.parse("01/01/2020");
String formattedDate = targetFormat.format(inputDate);
java.util.Date outputDate = targetFormat.parse(formattedDate);
java.sql.Date sqlDate = new Date(outputDate.getTime());
System.out.println(" Sql Date "+sqlDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutPut: Sql Date 2020-01-01 // we need it as 01-01-20