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
Let me know if you figure out how to get yesterday? Thanks!
Joined: Apr 17, 2001
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
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.
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.