Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Datetime to JAVA Date

im getting the SQL Server datetime (1 Jan 2013) form the SqlRowSet like

while (rs.next()) {
 myBean.setDateProp(rs.getString(4));
}

the type of myBean DateProp is java.util.Date, is there a way to convert (1 Jan 2013) to java Date representation.

i have tried the following code

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss.SSS");
Date date=new Date();        
    try {
        date = sdf.parse("1 Jan 2013");           
    } catch (Exception e) {
        e.printStackTrace();

    }       

and i get the ParseException

SEVERE: java.text.ParseException: Unparseable date: "1 Jan 2013"

any directions...

like image 788
Dakait Avatar asked Jul 13 '26 07:07

Dakait


1 Answers

try this -

SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
Date date=new Date();        
try {
    date = sdf.parse("1 Jan 2013");           
}catch (Exception e) {
    e.printStackTrace();
}   
like image 139
Subhrajyoti Majumder Avatar answered Jul 14 '26 20:07

Subhrajyoti Majumder