• 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

DateFormat Error

 
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!
 
Ranch Hand
Posts: 93
IntelliJ IDE VI Editor Java
  • 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 VI Editor Java
  • 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 VI Editor Java
  • 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 VI Editor Java
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read my previous posts... Your format string is missing 'de' preposition...
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the JavaDatesFaq for parsing String to Date.
 
What are your superhero powers? Go ahead and try them on this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic