Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with date arithmetic

Status
Not open for further replies.

lowbk

Technical User
Nov 26, 2001
162
SG
hello, i've a date in the format yyyy-mm-dd and i want to add a day to it.
below is my code, but i don't know why the answer isn't correct. the output is 1999-1-1 (which is wrong!)

pls advise


String visitdate="1999-12-31";
SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd");
Date vdate = df.parse(visitdate);
Calendar rightnow = Calendar.getInstance();
rightnow.setTime(vdate);
rightnow.add(Calendar.DATE,1);
System.out.println(""+rightnow.get(Calendar.YEAR)+"-"+rightnow.get(Calendar.MONTH)+"-"+rightnow.get(Calendar.DAY_OF_MONTH));
 
i found the answer to it.
the second line is wrong.
it should be ("yyyy-MM-dd") instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top