Ami*_*Ami 44 java simpledateformat parseexception
我在尝试使用代码时正在解析异常
    String date="Sat Jun 01 12:53:10 IST 2013";
    SimpleDateFormat sdf=new SimpleDateFormat("MMM d, yyyy HH:mm:ss");
    Date currentdate;
    currentdate=sdf.parse(date);
    System.out.println(currentdate);
例外
    String date="Sat Jun 01 12:53:10 IST 2013";
    SimpleDateFormat sdf=new SimpleDateFormat("MMM d, yyyy HH:mm:ss");
    Date currentdate;
    currentdate=sdf.parse(date);
    System.out.println(currentdate);
输入:Sat Jun 01 12:53:10 IST 2013
预期产量:Jun 01,2013 12:53:10
怎么解决这个?
ass*_*ias 99
你的模式根本不符合输入字符串...它不起作用也就不足为奇了.这可能会更好:
SimpleDateFormat sdf = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy",
                                            Locale.ENGLISH);
然后要使用您所需的格式打印,您需要第二个SimpleDateFormat:
Date parsedDate = sdf.parse(date);
SimpleDateFormat print = new SimpleDateFormat("MMM d, yyyy HH:mm:ss");
System.out.println(print.format(parsedDate));
笔记:
图案不对
    String date="Sat Jun 01 12:53:10 IST 2013";
    SimpleDateFormat sdf=new SimpleDateFormat("E MMM dd hh:mm:ss Z yyyy");
    Date currentdate;
    currentdate=sdf.parse(date);
    System.out.println(currentdate);
        String date="Sat Jun 01 12:53:10 IST 2013";
        SimpleDateFormat sdf=new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy");
        Date currentdate=sdf.parse(date);
        SimpleDateFormat sdf2=new SimpleDateFormat("MMM dd,yyyy HH:mm:ss");
        System.out.println(sdf2.format(currentdate));
| 归档时间: | 
 | 
| 查看次数: | 216352 次 | 
| 最近记录: |