Solved

Java Date

Posted on 2001-08-01
4
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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:
Suggested Courses

630 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