File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to round up year duration. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to round up year duration." Watch "How to round up year duration." New topic
Author

How to round up year duration.

Lim Cody
Greenhorn

Joined: Jul 02, 2007
Posts: 6
Let say start date is 25/5/2000 and end date is 25/6/2000. The duration in month is 1 month only then i need return 1 year. Example: if the actual duration is 2 years 3 month the method return 3 years. Can someone help me? Thanks.
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
So if hte duration is less than 365 days, you want your app to display one year. If it is less than 3*365 days, you want it to display 3? I wonder what would happen if your application divided 30 days by some constant equal to the number of days in a year?
Lim Cody
Greenhorn

Joined: Jul 02, 2007
Posts: 6
yes, Chad Clites's solution is good. but i don't know how to get number of days in a year (365 or 366)? example 25/5/2000 to 24/5/2001 should return 1 year (365 days) and 25/5/2003 to 24/5/2004 (leap year) also return 1 year (366 day).
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Use the java.util.Calendar class for computing the year of both days.

Subtract the values of the years and add one to it.

Java.Util.Calendar


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
 
 
subject: How to round up year duration.