java - When using GregorianCalendar and adding 4 years, why does it appear further in date? -


i've completed assignment , output appears work except fact results projgraddate or graduation date should 4 years greater enrollment date. why appear if it's more 4 years or 5 years?

my results after running program follows

enrollment date: 10/14/2013 graduation date: 07/17/2018

this seems 5 years or overlooking something?

here code (first collegestudent class testcollegestudent application):

this.fname = fname; this.lname = lname; this.enteredenrollmentdate = enteredenrollmentdate; projgraddate = new gregoriancalendar(         enteredenrollmentdate.getinstance().get(enteredenrollmentdate.year),         enteredenrollmentdate.getinstance().get(enteredenrollmentdate.month),         enteredenrollmentdate.getinstance().get(enteredenrollmentdate.day_of_month)); projgraddate.set(projgraddate.year,  projgraddate.get(projgraddate.year) + 4 ); 

your code should start working when remove .getinstance(). tried this:

import java.text.dateformat; import java.text.simpledateformat; import java.util.calendar; import java.util.gregoriancalendar;  /**  * created http://stackoverflow.com/q/25353775/1266906  */ public class addtocalendar {     public static void main(string[] args) {         gregoriancalendar enrollmentdate = new gregoriancalendar(2013, calendar.october, 10);         gregoriancalendar graduationdate = new gregoriancalendar(enrollmentdate.get(calendar.year),                                                                  enrollmentdate.get(calendar.month),                                                                  enrollmentdate.get(calendar.day_of_month));         graduationdate.add(calendar.year, 4);          dateformat dateformat = simpledateformat.getdateinstance();         system.out.println(                 dateformat.format(enrollmentdate.gettime()) + " -> " + dateformat.format(graduationdate.gettime()));     } } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -