SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
should be
SimpleDateFormat format = new SimpleDateFormat("MMddyyyy");
return format.parse(value);
// value should be of Date type not String .
Try this to change format of the date from MMddyyyy to MM/dd/yyyy: It works fine for me.
public static void main(String[] args) throws ParseException {
BigDecimal bd = new BigDecimal(12051998);
String s = bd.toString();
System.out.println(s);
DateFormat originalFormat = new SimpleDateFormat("MMddyyyy");
DateFormat targetFormat = new SimpleDateFormat("MM/dd/yyyy");
Date date = originalFormat.parse(s);
String formattedDate = targetFormat.format(date);
System.out.println(formattedDate);
}
Output:
12051998
12/05/1998