This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

String to timestamp

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please clear me, what does this exception mean: Exception in thread "main" java.text.ParseException: Unparseable date: "06.10.2013 00:00". That was found such a date in file 06.10.2013 that cannot be parsed? must it be always 06/10/2013? i got it, when i convert String[] to Timestamp while reading file. What if i have two formats in a file like 03/10/2013 and 03.10.2013, wich one must i use then, instead of this :SimpleDateFormat dateFormat = new SimpleDateFormat(
"MM/dd/yyyy HH:mm");
 
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change your dots to slashes.
 
Marshal
Posts: 67273
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to accept multiple formats, you can try patterns for either. If one fails, try the other.

In this case, since the different is only the delimiters, you can try normalizing before parsing (as already suggested).
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the expected date format is dd.MM.yyyy then why not try



Also is the time part HH:mm added manually (eg not from the file)? If so, you should manually concatenate it with " 00:00" then use the pattern "dd.MM.yyyy HH:mm".

Better yet, if you worry the "." makes it unparsable, replace it with "/" and use the "dd/MM/yyyy HH:mm" pattern.
 
S Roberts
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have both time formats in my file 06.10.2013 and 06/10/2013, and can't change it to ones
 
lowercase baba
Posts: 12753
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you can't change it in the file, then change it after you've read it in...or try it with one pattern, and if that fails, try the other.
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
Java Code Review and Psychology
https://coderanch.com/t/714798/java/Java-Code-Review-Psychology
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!