File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes DateFormat Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "DateFormat Error" Watch "DateFormat Error" New topic
Author

DateFormat Error

matias casal
Ranch Hand

Joined: Oct 18, 2009
Posts: 61
Hello, does anyone know how to parse de following String ?

"Miércoles, 01 de Diciembre de 2010 01:00:00 a.m."

I am trying something like this , but it fails


My format is EEEE,dd MMMM yyyy HH:mm:ss aaa

Thanks!
Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

Your format string is "EEEE,dd... but your string is "Miércoles, 01... notice the whitespace between ',' and 01

Anyway, RAE says dates and moths must be writen in lowercase...


http://serfj.sourceforge.net - Simplest Ever REST Framework for Java
matias casal
Ranch Hand

Joined: Oct 18, 2009
Posts: 61
Thanks, but I tried



But the error continues
java.text.ParseException: Unparseable date: "Miércoles, 01 de Diciembre de 2010 01:00:00 a.m."

Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

There are several problems:

You missed prepositions 'de' in your format string, also for months' names is used MMMM not mmmm, furthermore, aaa means AM or PM, not 'a.m.' or 'p.m.'

This works, but notice AM at the end...

Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

If you can, use this way to format and parse...



It's easier to maintain.
matias casal
Ranch Hand

Joined: Oct 18, 2009
Posts: 61
Thanks.
Unfortunately, I cant use this string :


The string must be


I tried with
but
java.text.ParseException: Unparseable date: "Miércoles, 01 de Diciembre de 2010 01:00:00 a.m."
Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

Yes, It's unparseable because that format is for CET times... as I said you, there's no way to parse a.m. or p.m. that's not a valid format, it must be AM or PM.
matias casal
Ranch Hand

Joined: Oct 18, 2009
Posts: 61
but can I parse this String ?


This throws the same error
java.text.ParseException: Unparseable date: "Miércoles, 01 de Diciembre de 2010 01:00:00"

Eduardo Yañez Parareda
Ranch Hand

Joined: Oct 09, 2008
Posts: 92

Read my previous posts... Your format string is missing 'de' preposition...
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3054
    
  33

Please read the JavaDatesFaq for parsing String to Date.


Mohamed Sanaulla | My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DateFormat Error
 
Similar Threads
How to get Date Format of a System??
help getting user supplied dates to display
java.text.ParseException: Unparseable date
Queston about formatting date
getting datetime from Long