convert "01-Apr-08.12:38:04" to Date object

M

mike

Hi,

How can I convert this:

String time = "01-Apr-08.12:38:04";

SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy'.'hh:mm:ss ");

try {
Date date = dateFormat.parse(time);
} catch (ParseException e) {
e.printStackTrace();

}

I get the following:

java.text.ParseException: Unparseable date: "01-Apr-08.12:38:04"
at java.text.DateFormat.parse(DateFormat.java:337)


Any ideas on how I can work around this?

//mike
 
E

Eric Sosman

Hi,

How can I convert this:

String time = "01-Apr-08.12:38:04";

SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy'.'hh:mm:ss ");

try {
Date date = dateFormat.parse(time);
} catch (ParseException e) {
e.printStackTrace();

}

I get the following:

java.text.ParseException: Unparseable date: "01-Apr-08.12:38:04"
at java.text.DateFormat.parse(DateFormat.java:337)


Any ideas on how I can work around this?

As you've constructed it, `dateFormat' requires a trailing space,
but `time' doesn't have one.

Also, I'm not too sure that using "hh" without an AM/PM indicator
is a good idea. It's possible that parse() objects to the ambiguity.
 
M

mike

Den tisdagen den 22:e april 2014 kl. 15:03:42 UTC+2 skrev Eric Sosman:
As you've constructed it, `dateFormat' requires a trailing space,

but `time' doesn't have one.



Also, I'm not too sure that using "hh" without an AM/PM indicator

is a good idea. It's possible that parse() objects to the ambiguity.





--

Eric Sosman

(e-mail address removed)

Hi,

yes I unintentionally added a space at the end and of course I should use HH.

Thanks alot.

//mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,991
Messages
2,570,212
Members
46,800
Latest member
Tobi1987

Latest Threads

Top