• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date and time calculation

 
bijoy bose
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34214
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnks Folks...atlast i got it

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic