Formatter.parse returns a Date object, and Date.toString generates formats it the way you describe. To print a Date in a different format, you need to use the Formatter.format method.

As an aside, you could also use a SimpleDateFormatter pattern like "yyyymmdd" to parse the fileDate string, instead of doing it manually.

Naveen Mishra
Ranch Hand

Joined: Nov 20, 2005
Posts: 75

posted Mar 24, 2006 06:49:00

0

Hi Ulf, Thanks for your quick response. you said right , that using Formatter.format method we can get the date printed in the desired format. But , is it really posible to remove that time and timezone from the date object get from Formatter.format. ( I know it sounds absurd , but this is what the requiremnt is ... )

Thanks for being so co-operative.

Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42954

73

posted Mar 24, 2006 07:10:00

0

What do you mean by "from the date object get from Formatter.format"? the format method returns a String; the parse method returns a Date.

You can't "remove" the time from the Date object, but using a Formatter you can create a string representation of the Date object any way you like, and in particular without time and timezone.

The function formatter.parse(finalDate), is creating a Date Object and when call the toString() function it will print the entire date details. So if you want to get the selected fiels, then you can use formatter.format(date).

But in your case it will be formater.format(formatter.parse(finalDate)) which will return the same value that of "finaldate" )