• Post Reply Bookmark Topic Watch Topic
  • New Topic

String to timestamp  RSS feed

 
S Roberts
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");
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change your dots to slashes.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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).
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • 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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12564
49
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!