Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.text.ParseException: Unparseable date

htran_888Aug 20 2010 — edited Aug 31 2010
Hi All,

I am having minor difficulty spliting a date & time string and storing them in Date object to be persisted in MySQL database using JPA.

Below is the related code snippet of PrintDateTime.java:
1             String date_time_string = "10/09/2005 01:30:10 pm";
 2             System.out.println("date_time_string:" + date_time_string);
 3             SimpleDateFormat parse = new SimpleDateFormat("dd/MM/yyyy");
 4             SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
 5             Date date_parsed = parse.parse(date_time_string);
 6             System.out.println("Date: " + formatter.format(date_parsed));
 7
 8             SimpleDateFormat time_parse = new SimpleDateFormat("hh:mm:ss a");
 9             SimpleDateFormat time_formatter = new SimpleDateFormat("hh:mm:ss a");
10            Date time_parsed = published_time_parse.parse(date_time_string);
11            System.out.println("Time: " + time_formatter.format(time_parsed));
date_time_string:10/09/2005 01:30:10 pm
Date: 10/09/2005

*20/08/2010 5:01:11 AM PrintDateTime*
SEVERE: null
java.text.ParseException: Unparseable date: "10/09/2005 01:30:10 pm"
at java.text.DateFormat.parse(DateFormat.java:337)
at PrintDateTime.main(PrintDateTime.java:10)

I don't mind storing only a single date and time string and retrieve/format it separately for displaying purpose, as long as the content could be used for date/time comparison outside of Java. e.g. either SQL or Crystal Report.

Thanks a lot,

Jack
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 28 2010
Added on Aug 20 2010
13 comments
17,891 views