File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 20271

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
I agree. Here's the link:
subject: JCalendar problem
jQuery in Action, 3rd edition