0

将 12 小时日期时间格式转换为 24 小时日期时间格式时,我无法解析日期。代码是

    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);

我得到的例外是

StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.text.ParseException: Unparseable date: "04/25/2012  9:00AM"
4

1 回答 1

1

您可以使用以下方式轻松格式化smalldatetime字段,

 SimpleDateFormat writeFormat=new SimpleDateFormat("MMM dd yyyy HH:mm"
                                                          ,Locale.US);
 String strDate=writeFormat.format(rs.getTimestamp(5));
于 2012-10-16T11:03:18.560 回答