i feel patronized, but flattered. so i'll do it.
This checks not only the month, but day of month.
import java.util.*
public String getSeason(Date today, int year){
// the months are one less because GC is 0-based for the months, but not days.
// i.e. 0 = January.
String returnMe = "";
GregorianCalender dateToday = new GregorianCalender(year, today.get(Calender.MONTH_OF_YEAR), today.get(Calender.DAY_OF_MONTH);
GregorianCalender springstart = new GregorianCalender(year, 2, 1);
GregorianCalender springend = new GregorianCalender(year, 3, 30);
GregorianCalender summerstart = new GregorianCalender(year, 4, 1);
GregorianCalender summerend = new GregorianCalender(year, 7, 31);
GregorianCalender fallstart = new GregorianCalender(year, 8, 1);
GregorianCalender fallend = new GregorianCalender(year, 9, 31);
GregorianCalender winterstart = new GregorianCalender(year, 10, 1);
GregorianCalender winterend = new GregorianCalender(year, 1, 28);
if ((dateToday.after(springstart) && dateToday.before(springend)) || dateToday.equals(springstart) || dateToday.equals(springend)){
returnMe = "Spring";
else if ((dateToday.after(summerstart) && dateToday.before(summerend)) || dateToday.equals(summerstart) || dateToday.equals(summerend)){
returnMe = "Summer";
else if ((dateToday.after(fallstart) && dateToday.before(fallend)) || dateToday.equals(fallstart) || dateToday.equals(fallend)){
returnMe = "Fall";
else if ((dateToday.after(winterstart) && dateToday.before(winterend)) || dateToday.equals(winterstart) || dateToday.equals(winterend)){
returnMe = "Winter";
else {
returnMe = "Invalid";
}
return returnMe;
}
I'm sure this is hideous, and can be improved. let me know in the comments.