The problem that you are having is that the Date class is not really about
dates... it's about time.

The easiest way to get yesterday's date is this:

Calendar theDate = Calendar.getInstance();  // returns a new locale-specific
calendar set to the current time.
theDate.add(Calendar.DATE, -1);

For printing or formatting, you use the DateFormatter class, and extract the
suitable date from the Calendar.

DateFormatter dateformat = new DateFormatter(/* suitable format string here
*/);
dateformat.format(theDate.getTime());

When Sun ripped out the date functionality from the Date class, they really
should have renamed it to Time, but that would have broken too much legacy
code.

--
  /\\\   Robert Watkins                      |   Email: [EMAIL PROTECTED]
 (  )))  Software Engineer - Technology Dev. |      ph: +61 7 3303 3432
  \///   Mincom Limited                      |     fax: +61 7 3303 3257
 Mincom

This transmission is for the intended addressee only and is confidential
information. If you have received this transmission in error, please delete
it and notify the sender. The contents of this E-mail are the opinion of the
writer only and are not endorsed by Mincom Limited unless expressly stated
otherwise.


> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Sanjay Kumar
> Sent: Friday, 28 April 2000 15:36
> To: [EMAIL PROTECTED]
> Subject: Re: DATE IN JAVA
>
>
> Hi  Killamsetty,
>
> One way is that convert  todays date in milliseconds. Then subtract number
> of milliseconds in 24 hrs (24*60*60*1000) from it.
> Then make a date object by using above calculated milliseconds into
> constructor.
>
>      Date mydate=new Date();
>      long mymillidate=mydate.getTime();
>      mymillidate=mymillidate - 24*60*60*1000;
>      Date previousdate= new Date(mymillidate);
>
>
> Happy Programming,
>
> Sanjay Kumar
> Informica India Pvt Ltd
> Noida, India
>
>
>
> ----- Original Message -----
> From: Killamsetty, Atchutarao <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, April 28, 2000 9:56 AM
> Subject: Re: DATE IN JAVA
>
>
> > How to get yesterday's date.
> >
> > for April 1 2000 it should give March 31 2000
> >
> > Thanks & Regards,                                          Goldman
> > Atchutarao Killamsetty,                                  Sachs
> > GSAM-IT,Tokyo
> > Tel:03-5573-7871
> >
> >
> >
> > -----Original Message-----
> > From: Kishore Raghavan [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, April 28, 2000 6:35 AM
> > To: [EMAIL PROTECTED]
> > Subject: Re: DATE IN JAVA
> >
> >
> > Avatar,
> >
> > The Date constructor which you suggested is DEPRECATED.
> >
> > you can simply use
> >         java.util.Date today = new java.util.Date();
> >
> > Thanks
> > Kishore Raghavan
> >
> >
> >
> > -----Original Message-----
> > From: A mailing list about Java Server Pages specification and reference
> > [mailto:[EMAIL PROTECTED]]On Behalf Of AVATAR SINGH
> > Sent: Thursday, April 27, 2000 1:42 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: DATE IN JAVA
> >
> >
> > One of the many Ways:
> >  Calendar cal = Calendar.getInstance();
> >   int yr= (cal.get(Calendar.YEAR)-1900);
> >   int mnth=cal.get(Calendar.MONTH);
> >   int de=cal.get(Calendar.DAY_OF_MONTH);
> >   java.sql.Date  dateToday = new java.sql.Date(yr,mnth,de);
> >
> >
> > Munish Talwar wrote:
> >
> > > Hi,
> > >
> > > Can anybody tell me how can I find today's date in Java.
> > >
> > > In Oracle or Microsoft
> > >
> > > we use sysdate, or now to do this but in java what do we have for this
> > >
> > > Thanks
> > > Munish

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to