0

I am not able to parse date while converting 12hr datetime format to 24hr datetime format.the code is

    List_CallDateTime=rs.getString(5);
    System.out.print(List_CallDateTime);
    String str=List_CallDateTime;
    SimpleDateFormat callreadFormat=new SimpleDateFormat("MM/dd/yyyy hh:mm aa",Locale.US);
    SimpleDateFormat callwirteformat=new SimpleDateFormat("MMM dd yyyy HH:mm",Locale.US);
    Date calldate=null;
    calldate=callreadFormat.parse(str);
    String callcreatedate=callwirteformat.format(calldate);
    System.out.println("asdsad"+callcreatedate);

and the exception that I get is

StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.text.ParseException: Unparseable date: "04/25/2012  9:00AM"
4
  • The seconds are missing in the date you offer but the conversion format specifies seconds. Commented Oct 16, 2012 at 10:03
  • Cleared but still i get the same exception again Commented Oct 16, 2012 at 10:14
  • What is the datatype of table field? Commented Oct 16, 2012 at 10:22
  • You should have to call getTimestamp method. e.g callwirteformat.format(rs.getTimestamp(5)) Commented Oct 16, 2012 at 10:46

1 Answer 1

1

You can easily format the smalldatetime field using,

 SimpleDateFormat writeFormat=new SimpleDateFormat("MMM dd yyyy HH:mm"
                                                          ,Locale.US);
 String strDate=writeFormat.format(rs.getTimestamp(5));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.