This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Unparseable date exception....!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Unparseable date exception....!!!!" Watch "Unparseable date exception....!!!!" New topic
Author

Unparseable date exception....!!!!

Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
Hi,

I'm getting the following exception when I try to parse a string date and I don't know what I'm doing wrong:

Unparseable date: "Mon Aug 20 18:30:00 PDT 2007"

Here's my source code:

public String getTime(String dt)
{
....

DateFormat datafmt = new SimpleDateFormat("h:mm a");
Date date = datefmt.parse(dt);

//textTime = DateFormat.getTimeInstance(DateFormat.SHORT).format(date);

....


}

Thanks in Advance!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Your string is "Mon Aug 20 18:30:00 PDT 2007", but your format only allows an hour, minute and AM/PM. If the string was "1:30 PM" it would have been ok.

You either have to change the input string or the format.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
THaNks!!!

DateFormat datefmt = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");

I changed the format and it work!!!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Unparseable date exception....!!!!
 
Similar Threads
Strange behavior of java.text.DateFormat
Can't parse dates with full zone name
Date Formatting
Strange behaviour of java.text.DateFormat
Problem in SimpleDateFormat