aspose file tools*
The moose likes Java in General and the fly likes java.text.ParseException: Unparseable date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.text.ParseException: Unparseable date" Watch "java.text.ParseException: Unparseable date" New topic
Author

java.text.ParseException: Unparseable date

Monica Marugan
Greenhorn

Joined: Feb 26, 2008
Posts: 6
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

Joined: Oct 29, 2001
Posts: 8900
    
    8

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Monica Marugan
Greenhorn

Joined: Feb 26, 2008
Posts: 6
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

Joined: Aug 16, 2005
Posts: 14144
    
  18

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


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8900
    
    8

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

Joined: Feb 26, 2008
Posts: 6
Give me the same error.

more helps?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8900
    
    8

What does your code look like now?
Monica Marugan
Greenhorn

Joined: Feb 26, 2008
Posts: 6
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

Joined: Oct 29, 2001
Posts: 8900
    
    8

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

Joined: Feb 26, 2008
Posts: 6
Thank you!!!

It's work ok thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.text.ParseException: Unparseable date