Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding Dates from Local System

 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
this is a complex problem for me hopefully some of your suggestions will be helpful.
I want to find the future Date based on a selected day.
Suppose this is calendar for this month March 2004
March 2004
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Now if I want to find the 6th day from today means as today is(Marh 20th)
and now I want to know what will be date on next 6th day(i.e March 26th)
How to find this?
Here I will use system date/calendar to get the current date but sometime I need to know 6th day from some of the previous date.
eg if I want to know 6th day from 12th march then how to do this.
If it looks unclear pls reply bak, Or just tell me how I can get he next sixth day for any date using system date time.
thanks in advance
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into GregorianCalendar class. There is an add() method that adds a number of days or months or years or whatever. Use a negative number to subtract.
Now, Java is definitely messed up when it comes to dates. You've got Date classes in util and sql, and GregorianCalendar. Converting between them can be maddening. Be patient, look for a good book on the subject (Thinking in Java is free here: http://64.78.49.204/) or hope somebody smarter than me chimes in
 
ChandraMouli Vidiyala
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anurag,
check this out.....
Calendar curDate = Calendar.getInstance();
System.out.println("Current Date is : " + curDate.getTime());
Calendar dateAfter10Days = Calendar.getInstance();
dateAfter10Days.add(Calendar.DAY_OF_YEAR, 10); // Adds 6 days to the current date
System.out.println("Date after 10 days is : " + dateAfter10Days.getTime());
-Mouli
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic