• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

converting string yyyy/MM/dd to java.util.Date

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have getting date object as Mon Jan 24 00:00:00 IST 2000
i have have converted it in the form yyyy/MM/dd using SimpleDateFormat class. But i am getting the converted date as String form.
But i want it in date form itself.
can anybody suggest me how to do this.
. Date d=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");
String _format=sdf.format(d);
System.out.println("the date is:"+_format);

Thu Mar 22 20:51:35 IST 2007
the date is:2007/03/22 --> I want this date as java.util.Date but it is returning in string format.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Your Date object hasn't changed at all. When you format a Date with SimpleDateFormat, you get a String but the Date object remains intact. Your code is working fine.
SimpleDateFormat is used to format dates to be shown as needed, and to parse strings that represent dates to a Date object.
If what you need is to get the date written in any other format, just create another instance of SimpleDateFormat, and use the same Date object.
I hope this helps.
Pablo.
 
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can only display an object by formatting it, in some way, as a string. So it doesn't make sense to say that you want to see a date "as java.util.Date" in your output.
 
reply
    Bookmark Topic Watch Topic
  • New Topic