aspose file tools*
The moose likes Beginning Java and the fly likes java.util.Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.util.Date" Watch "java.util.Date" New topic
Author

java.util.Date

kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
Hi,
a couple of questions about Dates. The most pressing one is this : I have today's date, and I have it nicely formatted. Call it theDate. How can I use get at yesterday's date, without introducing a new variable, and without changing the value of theDate ?
The less urgent problem is that I'm using these deprecated methods, getDate and setDate, and I don't understand how I can do much without them - can anyone suggest an easy explanation or something to read ?
Many thanks,
Kate
Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
import java.util.Date;
import java.text.*;
public class GetDate
{
public static void main(String arg[])
{
Date now = new Date();

System.out.println("right now is : " + now.toString());
}
}
You won't get depreciation while compiling the above code
for more information read the http://java.sun.com/doc/books/tutorial/il8n/format/simpleDateFormat.html

Let me know if you figure out how to get yesterday?
Thanks!
kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
Hi Mindy,
It's really when I do the yesterday thing that I run into problems... using your 'now', I can do :

to make 'now' into yesterday's date. However, this is where setDate and getDate are the deprecated methods. (and also, where I would like to get at yesterday's date without affecting 'now')
Cheers,
Kate
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Kate,
I don't know about keeping the original value the same, but you should be using java.util.Calendar. Look specifically at the add method. The API shows how to subtract using it ...
Regards,
Manfred.
A Agrawal
Ranch Hand

Joined: Jul 13, 2001
Posts: 41
I don't know whether you would like this solution or not...but one simple and non deprecated way of doing it -
<code>
Date dtNow = new Date(); ///this is your 'formatted date'
Date dtYesterday = new Date(); //last date
dtYesterday.setTime(dtNow.getTime() - 24 * 60 * 60 * 1000);
</code>

------------------
Amit Agrawal,
New Delhi, India.


Amit Agrawal,<BR>New Delhi, India.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.util.Date