Hi all,

I found that setLinent() method of the simple date format
doesn't do a nice job.

When i executed the following program
------------------------------------------------------------
import java.sql.Date;
import java.text.SimpleDateFormat;

public class DateTest {

 public static void main(String[] args) {
  try {
   SimpleDateFormat sdf = new SimpleDateFormat("d/M/yyyy");
   sdf.setLenient(false);
   String s = "20/2/2003This is an incorrect year";

   System.out.println("abhay: s = " + s);
   System.out.println("abhay: parse o/p = " + sdf.parse(s));

   Date parsedDate = new Date((sdf.parse(s)).getTime());
   System.out.println("abhay: parsedDate = " + parsedDate);
  }
  catch (Exception e){
   System.out.println("abhay: Error indate format !!");
  }
 }
}
-----------------------X-------------------------------------
it gave me an output ...

------------------------------------------------------------
abhay: s = 20/2/2003This is an incorrect year
abhay: parse o/p = Thu Feb 20 00:00:00 GMT+05:30 2003
abhay: parsedDate = 2003-02-20
-----------------------X-------------------------------------

where you can see that the input date doesnt have a correct
year ! IMO parse() should throw ParseException. ...
is this a bug ???

Moreover the jocs say ..
------------------------------------------------------------
public Date parse(String source) throws ParseException

Parses text from the beginning of the given string to produce a date.
The method may not use the entire text of the given string.
------------------------------------------------------------
So I think in the above case, it gets the string "20/2/2003"
and ignores the "This is an incorrect year" and gracefully outputs
the date.

If this behaviour is justified .. then can anyone suggest a workaround ?

Thanks in advance.

regards
abhay
  ---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Reply via email to