codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Hello...  haripriya amaresan at 10:52 on Thursday, January 11, 2007
 

Hi everyone...

I have a doubt regarding the date in java.. i have to add two days with the present date. that is if the present date is '01/21/2006' and if we have to add 12 days then i should get '02/02/2006'.. i have tried one.. by taking the day part alone in the date and by adding.. but if we do like that then the result will be '01/33/2006' which is invalid. is there any other way????.....Pls help me to get thru this...

Thanks.


  Re: Hello...  crwood at 17:47 on Thursday, January 11, 2007
 


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CalendarAddition {
public static void main(String[] args) {
DateFormat df = new SimpleDateFormat("M/dd/yyyy");
Calendar calendar = Calendar.getInstance();
// Set the date to 21 Jan 2006
calendar.set(2006, 0, 21);
Date start = calendar.getTime();
System.out.println("start = " + df.format(start));
// Add twelve days to start.
calendar.add(Calendar.DAY_OF_MONTH, 12);
Date twelveDaysLater = calendar.getTime();
System.out.println("later = " + df.format(twelveDaysLater));
}
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Small Java Program Help
•  Some questions about JS.
•  Some questions about JS.
•  Applying discount
•  Re: Hello...
•  Please Help Javascript College Assignment
•  PDF manipulation
•  Re: Submitting Iframes
•  Re: Problems with mkdir


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007