I want to convert my string into valid date format even months and days are optional
For Example, I have the following string like below
String date1 = "20-12-2021"
String date2 = "12-2021" i.e without day
String date3 = "2021" i.e without day & month
String date4 = "21" i.e without day, month & just last two digits of the year
I want to convert all the above strings format into the valid date with 'yyyy-mm-dd' format as below,
For date1, Date should be "2021-12-20"
For date2, Date should be "2021-12-01"
For date3, Date should be "2021-01-01"
For date4, Date should be "2021-01-01"
Could you please help me with this? Any info will be really helpful. I can't define single string formatted for parser since the string format is unpredictable in my scenario.