File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Date; Previous date, Calendar; Gregorian Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date; Previous date, Calendar; Gregorian" Watch "Date; Previous date, Calendar; Gregorian" New topic

Date; Previous date, Calendar; Gregorian

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Good day everyone.
I am somewhat stuck on something that seems so simple.
Q: I am trying to write a small app. which will accept the current day of a year and output the correct previous day and DATE. This should take into regards Leap year difference and anything else. I'd like to be able to do this possibly using 1 or a few of the methods that the Java API offers. Any assistance on this would be greatly appreciated.
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
This isn't as easy as it may look at first, Ther isn't an easy way to creat a Calendar or GregorianCalendar object from a string and any method to change a date is depricated. After some study a possible solution is :

The output is now
Enter a Date in mm/dd/yyyy format
Todays Date = 03/01/2000
Yesterdays Date = 02/29/2000
Enter a Date in mm/dd/yyyy format
Todays Date = 03/01/1900
Yesterdays Date = 02/28/1900
Enter a Date in mm/dd/yyyy foramt
Todays Date = 01/01/2000
Yesterdays Date = 12/31/1999

This is better I hope

[This message has been edited by Carl Trusiak (edited September 22, 2000).]

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

Thank you very much. I appreciate this. I had 1st thought it
was quite simple, but as I looked at it more closely, I saw
small problems. I suppose I was hoping for a buildt method
within the java.util.Date or Calendar classes for automatically
being able to convert dates. And even when I did mess around
with the logic, I ended up solving most of the problems but
leaving behind a few critical points. Thank you very much.
Feel free to ask any Qs as well.

Darwin Perez

Joined: Jul 24, 2006
Posts: 1
ur java date is very good- how about date in words?
I agree. Here's the link:
subject: Date; Previous date, Calendar; Gregorian
It's not a secret anymore!