Take the 2-minute tour ×

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

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.

share|improve this question

4 Answers 4

up vote 3 down vote accepted

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?

share|improve this answer

JXDatePicker maybe should be used only for date in concept but You can still collect full Java Date object from its Editor. Just use something like this:

JXDatePicker datePicker = new JXDatePicker();
datePicker.setFormats("dd-MM-yyyy HH:mm:ss");

  set in any way value inside datePicker

JFormattedTextField editor = datePicker.getEditor();
Date dateInDatePicker = (Date) editor.getValue();

Using it in such way You are available to collect whole Java Date object not trimmed to only date info.

share|improve this answer

Posting this for others who may visit this question, rather than the OP, as I'm sure you have got a solution by now.

This is a very useful solution. It's very easy to update and customise.


share|improve this answer

So simple. Just paste this into your class definitions part.

private JXDatePicker Today= new JXDatePicker(new Date()); 

This shows the system date like: "09.09.2014"
If your regional setting differs, then try formatting the date like:



No need to put any other stuff.

share|improve this answer

Your Answer


