• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

java.text.ParseException: Unparseable date

 
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.
 
Bartender
Posts: 9615
16
Mac OS X Linux 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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: 9615
16
Mac OS X Linux 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: 9615
16
Mac OS X Linux 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: 9615
16
Mac OS X Linux 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
 
You've gotta fight it! Don't give in! Read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic