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 date and time calculation 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 » Beginning Java
Bookmark "date and time calculation" Watch "date and time calculation" New topic
Author

date and time calculation

bijoy bose
Ranch Hand

Joined: Mar 27, 2004
Posts: 32
i know it may be very simple question, but i couldn't find answer to this anywhere.....

does java allows date manupulation or in other words if i want to add 90 days to a some specific day and want to what will be the answer, can we do that in java.

e.g: Date d = 9.10.05;
Date e;
and i want to know what will be 30 days after d and i wan to assign it to 'e'

please help???
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Bijoy,
Take a look at the Calendar.add() method. It lets you pass in an amount to add (or subtract) in any units you want.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

You can also take a look at these JavaWorld articles: Calculating Java dates and Working in Java time : Learn the basics of calculating elapsed time in Java - they do a nice job of explaining Date math in Java.
bijoy bose
Ranch Hand

Joined: Mar 27, 2004
Posts: 32
calendar.add(int, int) in in this format

but i have a specific date in hand say Date e = 11/01/00;
now i have to add 90 days to it and find out which day it will be??

help??
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You will also need Calendar.setTime(). If you look at the Java API documentation, you can easily find answers to such questions on your own with a little bit of effort. I strongly suggest that you follow the above link and find the docs for the version of Java that you are using. Being able to navigate the Java API docs is an essential skill when programming in Java, imo.

Layne


Java API Documentation
The Java Tutorial
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Originally posted by bijoy bose:
but i have a specific date in hand say Date e = 11/01/00;
now i have to add 90 days to it and find out which day it will be??

help??

Help is available in the first article (Calculating Java Dates) I suggested above. A direct quote from the article: "Also, you will see how to do elementary calculations with dates, such as calculating the date 90 days after another date." Sounds exactly like what you want to do. We can (and will) point you in the right direction, but no one here is going to do the work for you. You will not learn how to program if we did.

I also agree with Layne that learning how to read and extract things from the API docs is an essential skill. Those docs may seem a little daunting at first, but after a bit of time they become much easier to understand.
bijoy bose
Ranch Hand

Joined: Mar 27, 2004
Posts: 32
Thnks Folks...atlast i got it

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: date and time calculation