store current date and date 1 year from current in java -
i have setup store current date variable in java. trying figure out how store date of 1 year after current date.
import java.util.date; import java.text.simpledateformat; import java.text.dateformat; import java.util.scanner; import java.util.calendar;
here have current date:
dateformat newdate = new simpledateformat("mm/dd/yyyy"); date date = new date(); startdate = newdate.format(date);
so if today illustration store 2/18/2013. trying store date 2/18/2014. how go doing this?
if not want drag external libraries, utilize calendar.add(calendar.year, 1)
calendar cal = calendar.getinstance(); date today = cal.gettime(); cal.add(calendar.year, 1); // previous year add together -1 date nextyear = cal.gettime();
note, if date 29/feb/2012
, added 1 year, 28/feb/2013
java date
No comments:
Post a Comment