Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Date object returns wrong month, day.

2 posts in JDBC Connect (product renamed to JConnect) Last posting was on 1997-06-16 12:32:30.0Z
Gene Barkin Posted on 1997-06-13 20:01:58.0Z
Message-ID: <33A1A736.33A41EBD@musc.edu>
Date: Fri, 13 Jun 1997 16:01:58 -0400
From: Gene Barkin <barking@musc.edu>
Reply-To: barking@musc.edu
Organization: Medical University of South Carolina
X-Mailer: Mozilla 4.0b5 [en] (Win95; I)
MIME-Version: 1.0
Subject: Date object returns wrong month, day.
X-Priority: 3 (Normal)
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 24
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:685
Article PK: 252437

I'm having a problem displaying a date as a user-friendly string after I
retrieve it from Sybase.

The java.sql.Date object seems to have a bug: the toString() method
returns a valid date string, (in yyyy-mm-dd format) but for

java.sql.Date d = _rs2.getDate("since"); // get the date value...

concatenating date.getMonth() + "/" + date.getDay() + "/" +
date.getYear() yields incorrect results (the month is off by one, the
day is off in a way I can't determine, the year is correct).

Since java.sql.Date is a subclass of java.util.Date (which has been
deprecated) does anyone know if java.sql.Date going to be continue to
exist? Will there be java.sql.Calendar and java.sql.DateFormat objects
(from the new java.util.Calendar and java.text.DateFormat classes)?

Is there a better way to display returned date values in text fields?

Thanks

Gene Barkin
Software Engineer
Medical University of South Carolina
barking@musc.edu


Jim Ancona Posted on 1997-06-16 12:32:30.0Z
From: jim.ancona@geac.com (Jim Ancona )
Subject: Re: Date object returns wrong month, day.
Organization: Geac SmartStream
References: <33A1A736.33A41EBD@musc.edu>
X-Newsreader: News Xpress 2.01
Date: Mon, 16 Jun 1997 12:32:30 GMT
Message-ID: <YBGKRkke8GA.205@forums.powersoft.com>
Newsgroups: sybase.public.jdbcconnect
Lines: 61
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com!bos-janco
Xref: forums-1-dub sybase.public.jdbcconnect:676
Article PK: 252427


In article <33A1A736.33A41EBD@musc.edu>, barking@musc.edu wrote:
>I'm having a problem displaying a date as a user-friendly string after I
>retrieve it from Sybase.
>
>The java.sql.Date object seems to have a bug: the toString() method
>returns a valid date string, (in yyyy-mm-dd format) but for
>
>java.sql.Date d = _rs2.getDate("since"); // get the date value...
>
>concatenating date.getMonth() + "/" + date.getDay() + "/" +
>date.getYear() yields incorrect results (the month is off by one, the
>day is off in a way I can't determine, the year is correct).

Months are zero-based in java.util.Date.

From the Javadoc for Date.getMonth():
Returns the month represented by this date. The value returned is
between 0 and 11, with the value 0 representing January.

>Since java.sql.Date is a subclass of java.util.Date (which has been
>deprecated) does anyone know if java.sql.Date going to be continue to
>exist? Will there be java.sql.Calendar and java.sql.DateFormat objects
>(from the new java.util.Calendar and java.text.DateFormat classes)?

As far as I know, java.util.Date has not been deprecated. It has been reduced
to being a Date holder class with formatting and date calculation being
handled by java.text.DateFormat and java.util.Calendar respectively.

From the JDK 1.1.2 Date Javadoc:
The class Date represents a specific instant in time, with
millisecond precision.

Prior to JDK 1.1, the class Date had two additional functions.
It allowed the interpretation of dates as year, month, day,
hour, minute, and second values. It also allowed the formatting
and parsing of date strings. Unfortunately, the API for
these functions was not amenable to internationalization.
As of JDK 1.1, the Calendar class should be used to convert
between dates and time fields and the DateFormat class
should be used to format and parse date strings. The
corresponding methods in Date are deprecated.

>Is there a better way to display returned date values in text fields?

Use java.text.DateFormat.format().

>Thanks
>
>Gene Barkin
>Software Engineer
>Medical University of South Carolina
>barking@musc.edu

--
Jim Ancona jim.ancona@geac.com jpa@os.com
Opinions expressed are my own, and not those of my employer.