aspose file tools*
The moose likes Java in General and the fly likes Finding Dates from Local System Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Finding Dates from Local System" Watch "Finding Dates from Local System" New topic
Author

Finding Dates from Local System

Anurag Mishra
Ranch Hand

Joined: Jun 16, 2003
Posts: 121
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


SCJP 1.2
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
ChandraMouli Vidiyala
Greenhorn

Joined: Dec 19, 2002
Posts: 12
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
 
Don't get me started about those stupid light bulbs.
 
subject: Finding Dates from Local System