• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

String to timestamp

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change your dots to slashes.
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Why is the word "abbreviation" so long? And this ad is so short?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic