You should not be using the old out-dated Calendar
and Date
classes. Use LocalDate
instead.
Since the question still doesn't show the desired output, we can only guess, but something like this should do it.
LocalDate birthday = LocalDate.of(1999, 2, 2);
System.out.println("Birthday: " + birthday.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu: EEEE");
int thisYear = Year.now().getValue();
for (LocalDate date = birthday; date.getYear() <= thisYear; date = date.plusYears(1))
System.out.println(date.format(formatter));
Output
Birthday: February 2, 1999
1999: Tuesday
2000: Wednesday
2001: Friday
2002: Saturday
2003: Sunday
2004: Monday
2005: Wednesday
2006: Thursday
2007: Friday
2008: Saturday
2009: Monday
2010: Tuesday
2011: Wednesday
2012: Thursday
2013: Saturday
2014: Sunday
2015: Monday
2016: Tuesday
2017: Thursday
2018: Friday
2019: Saturday
2020: Sunday
To make it correctly handle someone who is born on the leap day (Feb 29), you might do it like this instead:
LocalDate birthday = LocalDate.of(2000, 2, 29);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d, uuuu: EEEE");
int thisYear = Year.now().getValue();
for (int year = birthday.getYear(); year <= thisYear; year++)
System.out.println(birthday.withYear(year).format(formatter));
Output
Feb 29, 2000: Tuesday
Feb 28, 2001: Wednesday
Feb 28, 2002: Thursday
Feb 28, 2003: Friday
Feb 29, 2004: Sunday
Feb 28, 2005: Monday
Feb 28, 2006: Tuesday
Feb 28, 2007: Wednesday
Feb 29, 2008: Friday
Feb 28, 2009: Saturday
Feb 28, 2010: Sunday
Feb 28, 2011: Monday
Feb 29, 2012: Wednesday
Feb 28, 2013: Thursday
Feb 28, 2014: Friday
Feb 28, 2015: Saturday
Feb 29, 2016: Monday
Feb 28, 2017: Tuesday
Feb 28, 2018: Wednesday
Feb 28, 2019: Thursday
Feb 29, 2020: Saturday