Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

Java Date

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
vinaykn
Asked:
vinaykn
  • 2
1 Solution
 
giamtrotCommented:
The java.util.GregorianCalendar add method does all of this.
0
 
ValeriCommented:
listening
0
 
giamtrotCommented:
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
 
vinayknAuthor Commented:
Thank you verymuch Trot....
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now