当我运行程序时,默认值是实际时间。有没有办法将默认值设置为" 00:00"?
Date date = new Date();
morningtimeSpinner = new JSpinner(new SpinnerDateModel());
morningtimeSpinner.setBorder(new LineBorder(Color.LIGHT_GRAY, 2, true));
morningtimeSpinner.setBounds(200,182,75,30);
contentPane.add(morningtimeSpinner);
JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(
morningtimeSpinner, "hh:mm a");
morningtimeSpinner.setEditor(timeEditor);
morningtimeSpinner.setValue(date);
morningtimeSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent arg0) {
dd = (Date) morningtimeSpinner.getValue();
}
});
答案 0 :(得分:2)
可以使用java.util.Calendar
// get calender for today's date
Calendar date = new GregorianCalendar();
// reset hour, minutes, seconds and millis to midnight
date.set(Calendar.HOUR_OF_DAY, 0);
date.set(Calendar.MINUTE, 0);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
或者,您也可以使用joda-time API
DateTime today = new DateTime().withTimeAtStartOfDay();