String to Date Conversion mm/dd/yy to YYYY-MM-DD in java [duplicate]

As you say the input is in a different format, first convert the String to a valid Date object. Once you have the Date object you can format it into different types , as you want, check.

To Convert as Date,

SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
date = formatter.parse(dateVlaue);

To Print it out in the other format,

SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
dateString = formatter1.format(date)

Leave a Comment