It's not a secret anymore!
The moose likes Beginning Java and the fly likes JCalendar problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JCalendar problem" Watch "JCalendar problem" New topic

JCalendar problem

Rus Corina
Ranch Hand

Joined: Jul 08, 2011
Posts: 90
If anyone here is familiar with JCalendar from toedter, i need some help. I created the component "d" of type JDateChooser, I set the information to be displayed in it to be like this: d.setDateFormatString("dd.MM.yyyy"); the problem is that it displays the date in this form only in the textfield, after i chose the date. In my program, if I try to get the date like this: d.getDate() it returns something like this: Thu Apr 19 17:02:50 EEST 2012. The question is: what can I do to get the date from d in the form dd.MM.yyyy?
Rob Spoor

Joined: Oct 27, 2005
Posts: 20193

Use a (Simple)DateFormat object. That's probably what the JDateChooser uses internally as well.
The thing is, Date objects don't really have a format. It just contains a moment in time. It does have a format from toString(), but that's more meant for debugging purposes. For anything else a DateFormat is the way to go, as it gives you control over how you want to format the Date.

How To Ask Questions How To Answer Questions
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: JCalendar problem
It's not a secret anymore!