I have a program that converts dates from numerical month/day/year format to normal format (e.g. December 31, 2010).
I don't want to import anything, or use a date object to go about what I'm doing.
Before moving on to finding the max number of days by year, I'm trying to do it by month. I'm trying to match up the month with the number of days (omitting Feb since it depends on if it's Leap Year).
This isn't working for me. I think it's because of the format.
try {
if (m == 1 && (d > 31 || d < 1)) { // jan
} else if (m == 3 && (d > 31 || d < 1)) { // mar
} else if (m == 4 && (d > 30 || d < 1)) { // apr
} else if (m == 5 && (d > 31 || d < 1)) { // may
} else if (m == 6 && (d > 30 || d < 1)) { // june
} else if (m == 7 && (d > 31 || d < 1)) { // july
} else if (m == 8 && (d > 31 || d < 1)) { // aug
} else if (m == 9 && (d > 30 || d < 1)) { // sept
} else if (m == 10 && (d > 30 || d < 1)) { // oct
} else if (m == 11 && (d > 30 || d < 1)) { // nov
} else if (m == 12 && (d > 31 || d < 1)) // dec
throw new DayException(day);
} catch (Exception e) {
throw new DayException(day);
}
Is there an easier way to validate the day?