i am using a piece of
java script to get a GUI display for a user to select a date for an application i am working on.
what i then want to do is to
test whether the date selected is plus or minus one year of the current date.
the users date is saved in Date format, but i am unable to isolate the YEAR attribute when converting it to a Calendar object. this is what iv tried so far:
deliveryDate = dateFormat.parse(deliveryDateStr); // the user inputted date
Calendar currentCalendar = new GregorianCalendar();
Calendar userCalendar = new GregorianCalendar();
userCalendar.setTime(deliveryDate);
if (userCalendar.get(Calendar.YEAR) > currentCalendar.get(Calendar.YEAR+1) || userCalendar.get(Calendar.YEAR) < currentCalendar.get(Calendar.YEAR-1)) {
throw new ParseException("Year out of bounds.", 1);
}
any ideas?