jSpinner2.getValue().toString()
is basically asking the returned object for whatever String
representation it has, in this instance, you're asking a Date
object to pass you back it's default String
representation.
Remember, Date
does not have any concept of a format, it's just a container for the number of milliseconds since the Unix epoch.
You will need to use a DateFormatter
of some kind to format the Date
value from the JSpinner
to the format you want...
A better solution would be to use some kind of date/time data type in you database...
Updated
The stored in the JSpinner
is a Date
object, it has no concept of a format. You will need to use some kind of DateFormatter
to take to from been a Date
to been a String
value formatted the way you want.
Object value = jSpinner2.getValue();
if (value instanceof Date) {
String time = new SimpleDateFormat("HH:mm").format(value);
t1.setHourBegin(time);
} else {
// Deal with the invalid value...
}