Solved

Java Date

Posted on 2001-08-01
4
184 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
Comment Utility
The java.util.GregorianCalendar add method does all of this.
0
 
LVL 16

Expert Comment

by:Valeri
Comment Utility
listening
0
 
LVL 1

Accepted Solution

by:
giamtrot earned 100 total points
Comment Utility
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
Comment Utility
Thank you verymuch Trot....
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

771 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

12 Experts available now in Live!

Get 1:1 Help Now