• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.text.ParseException: Unparseable date

 
Monica Marugan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the next code for parse to date in my application server local Tomcat 5.0.28 and work ok.

if(m_strType.equals("cadena")) {
System.out.println("Formateamos fecha con cadena : " + strValue);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
try {
Date fecha = sdf.parse(strValue);
SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yyyy",new Locale("es,ES"));
return(sdf2.format(fecha));
}
catch (Exception e) {
e.printStackTrace();
}

}

I put this class in other Tomcat 5.0.28 in other server and give me the next error:

java.text.ParseException: Unparseable date: "18-abr-2007 0:00:00"
.......

What's problem?
Thank you.
 
Joe Ess
Bartender
Posts: 9297
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My initial wild guess would be that the locales are different on the two computers. Try creating your first SimpleDateFormat instance using the locale and see if that works.
 
Monica Marugan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I change my code to:

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", new Locale("en,EN"));

with Locale and the same error in my tomcat work ok in the other tomcat give me the same error.

I don't understand.
Thank you
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the date string you are putting in: "18-abr-2007 0:00:00" has only one digit for the hour: "0:00:00". If you specify "HH:mm:ss", then Java probably expects two digits, so it should look like "00:00:00".

Try "H:mm:ss" for the format string. (I haven't tested it myself, but probably it works).
 
Joe Ess
Bartender
Posts: 9297
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With an input of "18-abr-2007 0:00:00" I think you want that locale to be Locale("es,ES").
Are you expecting English or Spanish input?
 
Monica Marugan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Give me the same error.

more helps?
 
Joe Ess
Bartender
Posts: 9297
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your code look like now?
 
Monica Marugan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy H:mm:ss", new Locale("es,ES"));

I probe this code and

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", new Locale("es,ES"));

and give me error.
more helps??
thank you
 
Joe Ess
Bartender
Posts: 9297
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the API Docs for Locale. The single string constructor takes the language code only (i.e. "es" or "en"). There is a two string constructor for specifying language and country ("es" and "ES" for Spain, for example).
This code works for me:
 
Monica Marugan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!!!

It's work ok thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic