convert a string of date to date object

Hi all,

I have this string"07/19/2007 10:16 AM"

i need to convert it to Date object. I have tried using format object, but it doesn't work right...

can you tell me how to do this?

thanks

[218 byte] By [happy2005a] at [2007-11-27 11:16:12]
# 1

You tried using the parse method of the DateFormat class?

If not, use that.

If you did, and it doesn't work, post your formatted code.

ChuckBinga at 2007-7-29 14:17:43 > top of Java-index,Java Essentials,Java Programming...
# 2

You tried using SimpleDateFormat and it didn't work?

HOW didn't it work?

The most likely reasons are that your pattern is wrong or that you do not understand the difference between what a Date object contains and what is displayed when you print it.

jschella at 2007-7-29 14:17:43 > top of Java-index,Java Essentials,Java Programming...
# 3

http://www.javaalmanac.com/egs/java.text/FormatDate.html

http://www.javaalmanac.com/egs/java.text/ParseDate.html

jverda at 2007-7-29 14:17:43 > top of Java-index,Java Essentials,Java Programming...
# 4

thank you guys,

SimpleDateformat works great....i was missing ' '

thanks again

happy2005a at 2007-7-29 14:17:43 > top of Java-index,Java Essentials,Java Programming...
# 5

possibly this:

date = new SimpleDateFormat().parse("07/19/2007 10:16 AM");

petes1234a at 2007-7-29 14:17:43 > top of Java-index,Java Essentials,Java Programming...
# 6

> [i]possibly[/i] this:

> [code]

> date = new SimpleDateFormat().parse("07/19/2007

> 10:16 AM");

> /code]

This assumes that the default pattern string for that Locale is the correct one for parsing that date.

I find it helpful to setLenient(false), too.

%

duffymoa at 2007-7-29 14:17:43 > top of Java-index,Java Essentials,Java Programming...