DateFormat

J

Jun

I tried to parse a date time string as following

DateFormat df = DateFormat.getDateTimeInstance();
dd = df.parse("Tue Jan 06 10:57:41 PST 2004");

but failed.

I even tried

DateFormat df = DateFormat.getDateTimeInstance();
Date d = new Date();
dd = df.parse(d.toString());

and also failed.

What kind of format does it really take?

thanks
 
C

Chris Smith

Jun said:
I tried to parse a date time string as following

DateFormat df = DateFormat.getDateTimeInstance();
dd = df.parse("Tue Jan 06 10:57:41 PST 2004");

but failed.

I even tried

DateFormat df = DateFormat.getDateTimeInstance();
Date d = new Date();
dd = df.parse(d.toString());

and also failed.

What kind of format does it really take?

The format expected by DateFormat instances returned by factory methods
is entirely dependent on the locale. There is absolutely no guarantee
that it will be a proper inverse of Date.toString, or that it will
accept any other specific format. Because of that, I suggest that you
don't use DateFormat instances from the static factory methods for
parsing. That's especially true if you know the exact format of the
input; in that case, use SimpleDateFormat to specify the format exactly.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top