Solved

Java Date

Posted on 2001-08-01
4
187 Views
Last Modified: 2010-03-31
I need a utility class which returns a previous date from current date, for example
   i) a date of before seven days/week days to currentdate
  ii) a date before one month to current date
  ii) a date before one year to current date.

It has to take consideration of all, whether 28 days or 29 days or 30 days or 31 days in a month or whether its a leap year or not...and all.

I need it with code. Can anyone guide me where can i get that class.

0
Comment
Question by:vinaykn
  • 2
4 Comments
 
LVL 1

Expert Comment

by:giamtrot
ID: 6343647
The java.util.GregorianCalendar add method does all of this.
0
 
LVL 16

Expert Comment

by:Valeri
ID: 6343774
listening
0
 
LVL 1

Accepted Solution

by:
giamtrot earned 100 total points
ID: 6343817
Just to add an example:

Date startingDay = ...

// Contains date of now
GregorianCalendar gc = new GregorianCalendar();

// Now Contains startindDay
gc.setTime(startingDay);

// A week has passed
gc.add( java.util.Calendar.DATE, 7);

// Go back in time
gc.add( java.util.Calendar.MONTH, -7);

// Retrieve the day we've got
Date endingDay = gc.getTime();

and so on ...

0
 

Author Comment

by:vinaykn
ID: 6344174
Thank you verymuch Trot....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now