Search code examples
javaswingdatepickersimpledateformatswingx

Getting time from JXDatePicker


Is it possible to get not only Date, but Date and Time from a JXDatePicker component?

I have configured the widget to show this format:

SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
JXDatePicker startTime = new JXDatePicker(System.currentTimeMillis); // This gets today's Date, but time appears as 00:00:00
startTime.setFormats(dateFormatter);

Whenever I select a day in the calendar, time is set to 00:00:00 even if it had any other value set manually. I don't care about that, but when I get JXDatePicker's value, I receive 00:00:00 even if it has been edited. For example, if write 2012-06-22 07:23:10 into my JXDatePicker and then call dateFormatter.format(startTime.getDate()), I'm receiving the String "2012-06-22 00:00:00".

I need to get time values. Is there any easy way to do this? If it's too hard, I could change to a diferent widget you suggest.


Solution

  • the JXDatePicker is only for extracting dates. It won't return any time. That explains why you are getting 00:00:00. You will have to find another one. maybe this is the one you are looking for:

    Is there any good and free Date AND Time Picker available for Java Swing?