I am using the SimpleDateFormatter
class to convert a string into a date. I have the following code which works for Feb 27, 2020:
SimpleDateFormat FORMATTER = new SimpleDateFormat("ddMM"); //always current year
Date TODAY = FORMATTER.parse("2702");
System.out.println(TODAY);
This resolves to the following date:
Fri Feb 27 00:00:00 UTC 1970
However, when I try the same for Feb 29, 2020 (a leap year), I get an error:
Code:
SimpleDateFormat FORMATTER = new SimpleDateFormat("ddMM"); //always current year
Date TODAY = FORMATTER.parse("2902");
System.out.println(TODAY);
Output:
Sun Mar 01 00:00:00 UTC 1970
Can someone please suggest a way so that I can take into account leap years as well, using this date format?
Thank you.