Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DateFormat Error

 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
IntelliJ IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
IntelliJ IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
IntelliJ IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can, use this way to format and parse...



It's easier to maintain.
 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
IntelliJ IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
IntelliJ IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read my previous posts... Your format string is missing 'de' preposition...
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the JavaDatesFaq for parsing String to Date.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic