Re: Date question
- From: rhino_redux@xxxxxxxx
- Date: 29 Jun 2006 13:34:50 -0700
Jean-Francois Briere wrote:
Change it to a java.util.Date with java.text.SimpleDateFormat.
Then change it to a java.sql.Date:
String dateStr = "01-May-2006"
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy");
java.util.Date date = sdf.parse(dateStr);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
You really need to add the line:
sdf.setLenient();
to your solution. Otherwise, an input date like 39-May-2006 would be
accepted as valid and the code would return an SQL date of June 8th.
Of course, if you WANT that behaviour, don't add the setLenient()! I'd
prefer to reject a date that was obviously invalid rather than
interpret it into something valid by omitting the setLenient(). I doubt
that if the user entered 39-May-2006 he did it because he really MEANT
to enter 08-Jun-2006.
--
Rhino
.
- References:
- Date question
- From: hoho123
- Re: Date question
- From: Jean-Francois Briere
- Date question
- Prev by Date: Re: cut and join mp3-files with known bitrate
- Next by Date: Re: J2ME Application Error
- Previous by thread: Re: Date question
- Next by thread: Re: Date question
- Index(es):