Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.text.ParseException: Unparseable date: "01:19 PM"

I just try to parse a simple time! Here is my code:

   String s = "01:19 PM";
        Date time = null;
        DateFormat  parseFormat = new SimpleDateFormat("hh:mm aa");
        try {
            time = parseFormat.parse(s);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

I am getting this exception:

java.text.ParseException: Unparseable date: "01:19 PM"
    at java.text.DateFormat.parse(Unknown Source)
like image 956
KostasC Avatar asked Aug 27 '14 10:08

KostasC


1 Answers

This works:

  public static void main(String[] args) throws Exception {
   String s = "01:19 PM";
   Date time = null;
   DateFormat parseFormat = new SimpleDateFormat("hh:mm a", Locale.ENGLISH);
   System.out.println(time = parseFormat.parse(s));
  }

ouputs:

  Thu Jan 01 13:19:00 KST 1970
like image 186
Nicolas Modrzyk Avatar answered Sep 22 '22 06:09

Nicolas Modrzyk