I want to change the string into the date formate for that I am using SimpleDateFormat
class. I am passing the string as String+Integer.toString(int)
from list of strings and SimpleDateFormat pattern
as an inputs.
Note: Instead of String+Integer.toString(int)
if I pass actual string like "Jan 09 2019" successfully convert string into the date. I tried a lot with different things.
dateList
is a list of "MMM dd" formate dates.
Adding year on that formate by doing dateList.get(5)+Integer.toString(year)
which is giving me parse exception <<-- Instead of this if I hardcode the date like Jan 09 2019
converting string into the date.
finalDatesInMMMDDYYYYFormat
is another list where I am saving the dates in MMM dd yyyy format.
Utils.parseDate
is a method I wrote in Utils class where I mentioned try-catch block.
int year = 2019;
private List<String> dateList = new ArrayList<>();
private List<Date> finalDatesInMMMDDYYYYFormat = new ArrayList<>();
final String testString = dateList.get(5)+Integer.toString(year);
finalDatesInMMMDDYYYYFormat.add(Utils.parseDate(testString, new SimpleDateFormat("MMM dd yyyy")));
Expected: Change the string into the date and add it to finalDatesInMMMDDYYYYFormat
Actual: Getting parse exception.