Re: date comes up wrong..

Sohaila Roberts <[email protected]> Tue, 27 Aug 2002 15:09:38 -0230
Newsgroups gmane.comp.windows.devel.java.general
Message-ID <[email protected]>
Ok another interesting thing.. the code below still gave me
tomorrow's date on 2 linux servers and a solaris machine but when run on
a window OS the gave the correct date. (same situation occurs with my
original code..)

On Tue, 27 Aug 2002, [email protected] wrote:
> I've always used the subclasses, GregorianCalendar and SimpleDateFormat,
> and they seem to work fine.  Here's an example:
>
>       /**
>        * today() return today's date as an XML value in the form yyyy-mm-dd
>        */
>       public static String today() {
>               SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
>               return sdf.format((new GregorianCalendar()).getTime());
>       }
>
> If it works for you, just change the format string to whatever you need.
>
> Cheers,
> Ed
>
>
> Original Message:
> -----------------
> From: Sohaila Roberts [email protected]
> Date: Tue, 27 Aug 2002 12:30:41 -0230
> To: [email protected]
> Subject: Re: [JAVA] date comes up wrong..
>
>
> The date on the client machine is the correct date..
> I'm using jdk 1.3.1_03-b03 and redhat 7.2
>
> On Tue, 27 Aug 2002, David Rosenstrauch wrote:
>
> > Calendar.getInstance() will give you a calendar set to the current
> > date/time of the client machine.  So if the date is wrong I would think it
> > has to be because the system date/time is wrong.
> >
> > Which JDK & OS are you using?
> >
> >
> > DR
> >
> >
> > At 10:17 AM 8/27/2002 -02-30, you wrote:
> > >Hi, I'm getting the date via
> > >
> > >/* Gets the current date and returns it as a string */
> > >     private String getCurDate()
> > >     {
> > >         Calendar d = Calendar.getInstance();
> > >         Date d1 = d.getTime();
> > >         DateFormat df = DateFormat.getDateInstance();
> > >         return df.format(d1);
> > >     }
> > >but it always thinks its a day ahead.. (like it thinks today is the 28th
> > >but its the 27th, and the date on my server and the machine that the
> > >applets comes up on says its the 27th also..)
> > >
> > >why is it doing that?
> > >
> > >I also tried
> > >/* Gets the current date and returns it as a string */
> > >     private String getCurDate()
> > >     {
> > >         Date d1 = new date
> > >         DateFormat df = DateFormat.getDateInstance();
> > >         return df.format(d1);
> > >     }
> > >
> > >but that gave the same result..
> > >
> > >thanks
> > >sohaila
> >
> > You can read messages from the JAVA archive, unsubscribe from JAVA,
> > or subscribe to other DevelopMentor lists at http://discuss.develop.com.
> >
>
> You can read messages from the JAVA archive, unsubscribe from JAVA,
> or subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
> --------------------------------------------------------------------
> mail2web - Check your email from the web at
> http://mail2web.com/ .
>
>

You can read messages from the JAVA archive, unsubscribe from JAVA,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.