Unexpected java SimpleDateFormat parse exception

32,164

It is a Locale issue. Use:

sdf = SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US);
Share:
32,164
Emilio
Author by

Emilio

Updated on July 22, 2022

Comments

  • Emilio
    Emilio almost 2 years

    I can't understand why this few lines

        Date submissionT;
        SimpleDateFormat tempDate = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
    
        public time_print(String time) {
            try {
              submissionT=tempDate.parse(time);
            }
            catch (Exception e) {     
              System.out.println(e.toString() + ", " + time);
            }
    
        }
    

    Cause exceptions and print out

        java.text.ParseException: Unparseable date: "Tue Mar 31 06:09:00 CEST 2009", Tue Mar 31 06:09:00 CEST 2009
    

    ... while the "unparsable" time is compliant with the format string i've passed to SimpleDateFormat().. Any Idea?

  • NikolaDjokic
    NikolaDjokic about 15 years
    It only works because of your default Locale matches the expected one.
  • golimar
    golimar almost 7 years
    Would be nice if the exception message was not just "Unparseable date" but also the position in the String where it failed...