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
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
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.
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.
http://www.javaalmanac.com/egs/java.text/FormatDate.html
http://www.javaalmanac.com/egs/java.text/ParseDate.html
> [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.
%