Problem in Converting String to Date

Hi All,I am having one String String date = "2006-01-17 15:19:57.0"I want to parse this String into Date object.I will really appriciate if somebody helps me out.Thanks.
[211 byte] By [garsuma] at [2007-10-2 10:00:38]
# 1
http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html
jverda at 2007-7-13 1:10:47 > top of Java-index,Java Essentials,New To Java...
# 2
java.text.SimpleDateFormatLook at the API for how parse works... it has a expressions for the various values etc and is quite simple and easy to use.
jverda at 2007-7-13 1:10:47 > top of Java-index,Java Essentials,New To Java...
# 3

Thanks for your response.

I am using following code

String date = "2006-01-17 15:19:57.0";

SimpleDateFormat sdfInput =

new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" );

try {

Date d = sdfInput.parse(date);

System.out.println("(Default) Today is " + d);

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

After running this I am getting following exception

java.text.ParseException: Unparseable date: "2006-01-17 15:19:57.0"

I will appriciate your help

Thanks

garsuma at 2007-7-13 1:10:47 > top of Java-index,Java Essentials,New To Java...
# 4

You're specifying a 'T' and a timezone in your format, but they're not present in the string you're parsing.

I'm assuming from the way you're printing out the date, that your thinking is along these lines: "sdfInput will parse the input string, no matter what format it's in, and will produce a Date object. That Date object wil have the format specified in sdfInput."

This is wrong on a couple of fronts:

1) DateFormat doesn't magically figure out what format it's supposed to use for the String it's parse()***. The String has to match the DF's format.

2) Dates don't have formats. Only Strings do. A Date object is just a long. There's no relationship whatsoever between the Date that you get from parse() and the format that was used to produce it. When you print out a Date as you're doing, its toString method is called, which in turn uses a default format for your Locale.

If you want to turn a date string in one format into a date string in another format, use two different DateFormat objects with two different formats. Date date = df1.parse(inputString);

String outputString = df2.format(date);

jverda at 2007-7-13 1:10:47 > top of Java-index,Java Essentials,New To Java...
# 5
***?
CeciNEstPasUnProgrammeura at 2007-7-13 1:10:48 > top of Java-index,Java Essentials,New To Java...
# 6
> ***?Apparently i-n-g is a naughty word. What the ffuck is up with that?
jverda at 2007-7-13 1:10:48 > top of Java-index,Java Essentials,New To Java...
# 7
> > ***?> > Apparently i-n-g is a naughty word. What the ffuck> is up with that?Okay I'm sorry but this is funny... are you ready for it....****-***ROLF!
jverda at 2007-7-13 1:10:48 > top of Java-index,Java Essentials,New To Java...
# 8
> > ***?> > Apparently i-n-g is a naughty word. What the ffuck> is up with that?One atempt at an explanation provided by Monica: http://en.wikipedia.org/wiki/List_of_fictional_curse_words
CeciNEstPasUnProgrammeura at 2007-7-13 1:10:48 > top of Java-index,Java Essentials,New To Java...
# 9
What in the name of all the is holy is going on here.... the filters are different for each forum? We have been well and truly danaed.
CeciNEstPasUnProgrammeura at 2007-7-13 1:10:48 > top of Java-index,Java Essentials,New To Java...