simpledateformat – java.text.ParseException: Unparseable date

simpledateformat – java.text.ParseException: Unparseable date

Your pattern does not correspond to the input string at all… It is not surprising that it does not work. This would probably work better:

SimpleDateFormat sdf = new SimpleDateFormat(EE MMM dd HH:mm:ss z yyyy,
                                            Locale.ENGLISH);

Then to print with your required format you need a second SimpleDateFormat:

Date parsedDate = sdf.parse(date);
SimpleDateFormat print = new SimpleDateFormat(MMM d, yyyy HH:mm:ss);
System.out.println(print.format(parsedDate));

Notes:

  • you should include the locale as if your locale is not English, the day name might not be recognised
  • IST is ambiguous and can lead to problems so you should use the proper time zone name if possible in your input.
        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));

simpledateformat – java.text.ParseException: Unparseable date

Pattern is wrong

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

Leave a Reply

Your email address will not be published.