• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String to Date...

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have String "Mon, Dec 12 2005".
I need to convert this in Date Object ... as soon as I Convert it into Date it is something like "Mon Dec 12 00:00:00 GMT+05:30 2005"

I don't want this "hh:mm:ss z" to be there at all.

I'm using SimpleDateFormate for my purpose ... the code is some thing like this




Thanks a lot for ur hints and suggestions .
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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" )

Regards,
Rosh
SimpleDateFormat formatter = new SimpleDateFormat("EEE, MMM dd yyyy"); System.out.println(formatter.parse(finalDate).toString()); // Mon Dec 12 00:00:00 GMT+05:30 2005
 
Naveen Mishra
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
Thanks a lot for your kind suggestions .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic