User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 384,015 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,239 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Nov 25th, 2007
Views: 5,200
Add n number of days to given date
java Syntax | 5 stars
  1. public static void main(String args[]) throws Exception {
  2. SetTest st = new SetTest();
  3. st.addDaysToDate("11/11/2007", 2);
  4. }
  5.  
  6. private void addDaysToDate(String date, int daysToAdd) throws Exception {
  7. Date todayDate = new Date();
  8. DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
  9. String strDate = sdf.format(todayDate);
  10. Date parsedDate = sdf.parse(date);
  11. System.out.println(strDate);
  12. System.out.println(parsedDate);
  13.  
  14. Calendar now = Calendar.getInstance();
  15. now.setTime(parsedDate);
  16. now.add(Calendar.DAY_OF_MONTH, daysToAdd);
  17. System.out.println(now.getTime());
  18. }
Comments (Newest First)
frodo_cute21 | Newbie Poster | Apr 18th, 2008
hi! can you help me with my java programming?? plssssssssssssssssssss!!! im new to the java. here's my problem..
pls do solve my problem.. thanks!!!
hope to hear from you soon???
pls make the code.. god bless!!!

Activity 2

Place all the files in a folder named ClassList.
1. Design a class named Date with the following attributes: month, date and year which is all of type integer.
2. Design a class named Person with the following attributes: name and address both of type String and birthday of type Date.
3. Design a class named Student which is a Person with the following additional attributes: id and year both of type integer and school and course both of type String.
4. Write a class named ClassList which contains an array of Student with the maximum capacity of 100. It should also have the following method:
public boolean add(Student s)
-adds the student to the array
public boolean edit(Student s)
-edit the student’s entries in the array
public boolean delete(int id)
- delete the student with the matching id number in the array
public Student search(int id)
-search the student record in the array
public void display()
- shows all the records of the student in the array
5. Design a GUI for the class list that would allow the add, edit, delete, search and display of the students.
javaAddict | Posting Pro in Training | Jan 7th, 2008
I would have suggested for the user to give the date format as well. Or perhaps a try-catch with a throw inside the catch in case the user didn't enter a valid date.
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 4:39 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC