Date Problem [message #132339] |
Fri, 12 August 2005 00:54 |
vikassheelgupta
Messages: 2 Registered: June 2005 Location: delhi
|
Junior Member |
|
|
hi,
i have a string in this format:-
String s = date+"-"+e_month+"-"+year;
and i want to covert it into
java.sql.Date sqlToday ;
so that i can save my values in the data base
i did every thing realted to that like:-
SimpleDateFormat ts= new SimpleDateFormat("dd-MM-yyyy");
sqlToday = new java.sql.Date(ts.parse(s).getTime());
but couldnt get the results
but if i use this
p="1-Aug-2005"
SimpleDateFormat ts= new SimpleDateFormat("dd-MM-yy");
if(p!=null)
{
sqlToday = ts.parse(s);
}
then the parsing error occurs bcz of "Aug" so tell me the solution if u have
so any one can help me
thanks
|
|
|
Re: Date Problem [message #135280 is a reply to message #132339] |
Tue, 30 August 2005 14:32 |
Art Metzer
Messages: 2480 Registered: December 2002
|
Senior Member |
|
|
public class OrafaqJava132339 {
public static void main (String[] args) {
String s = "1-Aug-2005";
java.text.ParsePosition pp = new java.text.ParsePosition(0);
java.text.SimpleDateFormat ts = new java.text.SimpleDateFormat("dd-MMM-yyyy");
java.sql.Date sqlToday = new java.sql.Date(ts.parse(s,pp).getTime());
}
} Look at your SimpleDateFormat constructor, you need another M and two more y's.
|
|
|