Solved

Java Date

Posted on 2001-08-01
4
199 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

734 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